Hi,
I was trying to enable lazy loading for my web application.
My typical requirment
1. Load a big hibernate object , place it in session and show it in multiple pages. User can edit the object.
2. Finally user can save whole changes or just skip saving by hittting "Cancel" button.
My problem
I loaded the big hibernate object, kept in web(work) session.
To display the object in 4 tabs, I used open-session-in-view concept and reattched the same object and made a open session available for entire request cycle. So the just displaying the object information (by lazy loading) in diffrent tabs is working.
2. But, I'm not able to save the updated object at the end.
Getting exceptions like "dirty collections"
=======================================
I found below statement from hibernate documentation, I'm kind of confused, how to solve my problem.
=======================================
You may also attach a previously loaded object to a new Session with merge() or lock() before accessing uninitialized collections (or other proxies). No, Hibernate does not, and certainly should not do this automatically, since it would introduce ad hoc transaction semantics!
The lock() method also allows an application to re-associate an object with a new session. However, the detached instance has to be unmodified!
The merge() method -
if there is a persistent instance with the same identifier currently associated with the session, copy the state of the given object onto the persistent instance
if there is no persistent instance currently associated with the session, try to load it from the database, or create a new persistent instance
the persistent instance is returned
the given instance does not become associated with the session, it remains detached
=========================================
Please suggest me how to solve my problem with current open session view intercptor.
Any alternatives also welcome. My main intenstion is to achive lazy loading thru out the app with mimimal code changes (it reasonably big code base, and unfortunately no lazy at all)
_________________ Bhim Bomma
|