Concerning Hibernate sessions and Long Running Conversations (LRC)
gimpy21 Jul 30, 2008 7:32 PMMy question boils down to this: if I merge a detached entity at the beginning of a LRC in objectA, shouldn't that merged entity be fully accessable without throwing a LazyInitializationException (LIE) in objectB which is also in the same LRC?
I have a seam managed hibernate session named session
:
<persistence:hibernate-session-factory name="hibernateSessionFactory"/>
<persistence:managed-hibernate-session name="session"
auto-create="true"
session-factory="#{hibernateSessionFactory}"/>and use it like this:
@In(required=false) private Session session;
I begin with a commandLink:
<a4j:commandLink value="Edit" action="#{blahSearcher.requestEdit}" ajaxSingle="true"/>which calls this to begin my LRC:
@Begin(nested=true, flushMode=FlushModeType.MANUAL, pageflow="edit-selection")
public String requestEdit()
{
toEdit = selected;
return "start";
}My process definition picks up from there and creates ObjectA and take me to the proper page:
@Name("objectA")
@Scope(ScopeType.CONVERSATION)
public class ObjectA extends SomeObject
{
@In(required=false)
private Client activeClient;
@In(required=false)
private Session session;
...
@Create
public void initialize()
{
activeClient = (Client)session.merge(activeClient);
...
}
...
I have to call session.merge() as activeClient
is a detached entity. I figured that since it is now
merged, it can be used on the next page in ObjectB:
@Name("objectB")
@Scope(ScopeType.CONVERSATION)
@AutoCreate
@Conversational
public class ObjectB implements Serializable
{
@In(required=false)
private Client activeClient;
...
public List<String> getStuff() { return activeClient.getStuff(); }
Calling objectB.getStuff() will result in a LIE but adding to objectB:
@In(required=false)
private Session session;
@Create
public void initialize() { source = (Client) session.merge(activeClient); }remedies the situation.
I'm thinking I'm missing something pretty basic, but I may in fact just not have as good of a handle on these things as I thought. Any help is appreciated. Thanks.