-
1. Re: Lazy collection load
sierras Jun 11, 2006 5:14 AM (in response to sierras)Obviouly is not the way because it does'nt work. I get an Exception
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: entities.Country.organizations, 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.readSize(AbstractPersistentCollection.java:97)
at org.hibernate.collection.PersistentBag.size(PersistentBag.java:222)
at beans.CountryBean.doRefreshWithOrganizations(CountryBean.java:142)
....
Any idea of what to do?
Thanks. -
2. Re: Lazy collection load
abl Jun 12, 2006 2:20 AM (in response to sierras)you have to use the entity returned from merge:
public Country RefreshCountryCollection(Country country)
{
country = em.merge(country);
country.getChildrenOrganizations();
return country;
} -
3. Re: Lazy collection load
wquraishi Aug 29, 2007 3:28 PM (in response to sierras)One thing I discovered is if you override the toString() method and output the relationships, it'll force the container to load the relationship related fields. I'm thinking it accomplishes the same thing as fetchtype.eager but i've had more luck with this. Plus it works dual fold since I use the toString() method in conjunction with facesMessages to display what the object coming back is.