[jboss-user] [EJB 3.0] - Re: How to lazily load collections?

michael.litherland do-not-reply at jboss.com
Mon Oct 16 16:31:00 EDT 2006


Yes, of course you're right the exception occurred when JSF tried to display the data model, so essentially when the JSP was rendered.


  |     public List<TdmAlerts> getAlertsFromEntity(MyEntity entity) {
  |         entityManager.refresh(entity);
  |         List<TdmAlerts> result = new ArrayList();
  |         result.addAll(entity.getTdmAlerts());
  |         return result;
  |     }
  | 

I changed the code to this and I get the same failure:


  | 16:22:55,838 ERROR [LazyInitializationException] failed to lazily initialize a collection of role: com.ati.raa.entities.MyEntity.tdmAlerts, no session or session was closed
  | org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.ati.raa.entities.MyEntity.tdmAlerts, no session or session was closed
  |         at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:358)
  |         at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:350)
  |         at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:343)
  |         at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
  |         at org.hibernate.collection.PersistentBag.toArray(PersistentBag.java:254)
  |         at java.util.ArrayList.addAll(ArrayList.java:473)
  |         at com.ati.raa.bl.EntityLogicBean.getAlertsFromEntity(EntityLogicBean.java:144)
  | 

So that refresh doesn't have the effect that I desired, namely to access that entity in the current session's context.  Any other thoughts?  Since the entity manager goes so far out of its way to hide the concept of sessions that it clearly depends on, it makes this hard for me to understand the right way to do this.

Also, what is this VO/TO you speak of?

Thanks much,
Mike

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

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



More information about the jboss-user mailing list