[jboss-user] [EJB 3.0] - Re: failed to lazily initialize a collection of role
Wolfgang Knauf
do-not-reply at jboss.com
Thu Nov 27 04:42:42 EST 2008
Hi Ramu,
the problem is the "fetchType" attribute on your relationship. It defaults to "FetchType.LAZY", which means that the other side of the relation is not loaded until required. If the entity gets detached and the relationship field is not loaded, you will get this exception on client side.
To work around you could
a) set the fetchType to "FetchType.EAGER" (not recommended for ManyToMany)
b) explicitely force loading the relationship field BEFORE the entity gets detached (before the session bean method is left).
To do so: call e.g. "student.getCourses().size();" after loading a student.
Calling only "student.getCourses();" does not help, you have to access the collection content to make it load.
Hope this helps
Wolfgang
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4192700#4192700
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4192700
More information about the jboss-user
mailing list