[jboss-user] [EJB 3.0] - Re: How to lazily load collections?
Wolfgang Knauf
do-not-reply at jboss.com
Tue Oct 17 05:45:36 EDT 2006
Hi Michael,
here is a sample snippet where accessing the relationship fails with your exception:
public MyEntity getEntity(object pk) {
| MyEntity entity = (MyEntity) entityManager.find(MyEntity.class, pk);
| //Will NOT load the data !
| entity.getTdmAlerts();
| return entity;
| }
I found that just accessing the collection property of the entity does NOT fetch its content.
You have to do something which forces the collection to load its items. In the following piece of code I access the collections size:
public MyEntity getEntity(object pk) {
| MyEntity entity = (MyEntity) entityManager.find(MyEntity.class, pk);
| int iSize = entity.getTdmAlerts().size();
| return entity;
| }
I suggest to add a parameter "boolean bFetchAlerts" to "getEntity" which controls whether the alerts are loaded or not.
I hope this helps
Wolfgang
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3978736#3978736
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3978736
More information about the jboss-user
mailing list