[jboss-user] [EJB 3.0] - Re: eager vs. lazy fetching

mazz@jboss.com do-not-reply at jboss.com
Fri Feb 23 09:19:19 EST 2007

Every time you call "find" you are getting back a new attached instance initialized according to the lazy-loading properties of your entity, i.e. it will not have any relationship info that is set to LAZY.  Even if you called that method from that servlet before.  I believe the same behavior occurs even if you call find() again immediately after the first find() in your session bean! The semantics of the find() method seem very clear to me on this point.  Every time you call it, you get a new instance initialized according to the lazy-loading properties.

Yes, obviously you need to call the size() method within your session bean because its only within there that you are still inside the scope of your entity manager and transaction.  Once you return back out into your servlet layer, you are no longer within the scope of the entity manager and it cannot manage your relationships anymore (i.e. you are detached at this point).  So, if you don't initialize your relationship collections prior to leaving your session bean, your servlet won't have it.

Side note: you might want to look into JBoss Seam - it provides the integration it sounds like you are looking for - that is, a seamless integration between the EJB/JPA layer and the servlet/JSF presentation layer.

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4021113#4021113

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4021113

More information about the jboss-user mailing list