-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Re attching objects
PostPosted: Wed Oct 24, 2007 7:55 pm 
Newbie

Joined: Sun Jul 03, 2005 6:27 pm
Posts: 7
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


Top
 Profile  
 
 Post subject: merge returns the persistent object ..
PostPosted: Mon Nov 05, 2007 8:53 pm 
Newbie

Joined: Sun Jul 03, 2005 6:27 pm
Posts: 7
Hi,

I found that merge() actually returns a persistent object with changes applied from dettached object.

Object newPersistentObject = session.merge(dettachedObject);

use "newPersistentObject" object and ignore "dettachedObject"

source: Book ,"Java Persistence with Hibernate"

_________________
Bhim Bomma


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.