Help

Controls

PermLinkWikiLink

Built with Seam

You can find the full source code for this website in the Seam package in the directory /examples/wiki. It is licensed under the LGPL.

Forum: Seam Users Forum ListTopic List
30. Jul 2008, 19:32 CET | Link

My 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.

2 Replies:
30. Jul 2008, 19:37 CET | Link

You need to outject the merged entity.

 

Read about how to report a bug.

Rating:  * * * * *
30. Jul 2008, 19:46 CET | Link

I spend all morning looking for a remedy, type up a post, and it comes to me right after I submit it. I come back to reply, and you beat me to it. Thanks, that was exactly what was needed.