I am facing problem with Hibernate Lazy initialization.
I tried to make lazy=true in mapping file, to improve the performance of the site.
without turning it to true, entire object tree is getting loaded into memory.
Following are the steps I followed
I made lazy=true for all classes, and the associations which each class possess.
-> I got LazyInitializationException: could not initialize proxy - the owning Session was closed
I started adding lazy to one class and it's associated classes. But problem was still there.
Added OpenSessionInViewFilter as follows to resolve above exception.
I started getting
-> HibernateSystemException: a different object with the same identifier value was already associated with the session: nested exception is org.hibernate.NonUniqueObjectException
To resolve NonUniqueObjectException, I tried to catch it and started using merge() supported by hibernate 3.0 as follows.
By doing all above steps I could resolve the problem only for few classes and relations.
If I try to enable lazy for others, I still get LazyInitializationException: could not initialize proxy - the owning Session was closed
This lazy problem has taken lot of efforts by now. I would appreciate if any one could suggest where I could be doing wrong.