I'm currently working on a project and I've encountered this error:
org.hibernate.TransientObjectException: object references an unsaved transient instance – save the transient instance before flushing
What happened: 1.) I have a session scope variable that I set after login, let's say SessionScopeVariableA.
2.) Then I have a page where I'm adding an entity, let's say EntityA.
3.) EntityA has a lazy field sessionScopeVariableA, so when I invoke the add method I have to set this variable.
entityA.setSessionScopeVariableA(sessionScopeVariableA);
em.persist(entityA);
4.) Note that SessionScopeVariableA is wrap in a session scope producer while the action is conversation scope.
5.) Whatever I do, I always end up with the transient error specified above.
Any idea?