-
1. Re: failed to lazily initialize a collection of role
wolfgangknauf Nov 27, 2008 4:42 AM (in response to mravikrish)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 -
2. Re: failed to lazily initialize a collection of role
mravikrish Nov 27, 2008 5:42 AM (in response to mravikrish)
Thanks wolfgang it worked