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

ALRubinger do-not-reply at jboss.com
Mon Oct 16 16:16:35 EDT 2006


Sorry; I assumed you were trying to iterate over the collection immediately after calling "refresh".  Where is the code generating the error?  Not in that SLSB snippit posted, but in the JSP?

The List returned from the EntityManager will be a Hibernate Collections class with a reference to the current session.  If you're just looking to get a "snapshot" of the current data in there at the time its requested, you can create a new List, put all of the items in the Entity bean's version in it, and safely return your list for use outside of the session/transaction. Assuming you're getting the error in the JSP:

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

...I think should do it.  Or use a TO/VO.

Manually closing is done by something like:

((HibernateEntityManager)entityManager.getDelegate()).getSession().close();  ... or similar

S,
ALR

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

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



More information about the jboss-user mailing list