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

eiben do-not-reply at jboss.com
Fri Feb 23 09:06:47 EST 2007


"mazz at jboss.com" wrote : So, Itemgroup has an items relationship that is lazy loaded.  Your findItemGroup is only loading in the Itemgroup entity without doing any fetch joining or eagerly loading of that relationship, hence your error.

well, but I though when I access the items-collection the first time, the data get's loaded from the database.

anonymous wrote : 
  | you will need to have another method, "findItemGroupWithItems" or something like that.  In that method you execute a query that does a JOIN FETCH, rather than use find().  Or you can do a find and then (still in findItemGroupWithItems method) immediately force the loading to happen by calling itemgroup.getItems().size() (this causes a second round trip to the database - not as efficient but easy to code up).

Do I have to make the call to the size attribute within my session-bean? It seems that it's not working as expected when I access that attribute from within my servlet.

I read in an book, that a workaround would be to use SFSB instead of SLSB, where the SFSB uses an extended persistent-context. This way I could make repeated requests to my entity as long as I don't remove the SFSB.

So I tryed something like this:


  | Itemgroup myItemGroup = getItemDispatcherExtended().findItemGroup(Integer.parseInt(request.getParameter("id")));
  | 
  | Collection<Item> myig = myItemGroup.getItems();
  | getItemDispatcherExtended().finished();
  | 

where the ItemDispatcherExtended is a SFSB


  | @Stateful
  | @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
  | public class ItemDispatcherExtendedBean implements IItemDispatcherExtended
  | {
  | 	@PersistenceContext(type = PersistenceContextType.EXTENDED) //, unitName = "business")
  | 	private static EntityManager em;
  | //...
  | }
  | 

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

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



More information about the jboss-user mailing list