-->
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.  [ 3 posts ] 
Author Message
 Post subject: Handling objects across different Hibernate sessions
PostPosted: Tue Sep 02, 2003 10:43 pm 
Beginner
Beginner

Joined: Tue Sep 02, 2003 9:28 pm
Posts: 25
Is there a way to take an object retrieved from one session and somehow associate it with a new session and have that new session process it as if it was the session that it was retrieved with?

In case that doesn't make sense (and it doesn't to me as I re-read it!), here's the scenario:

I've implemented the interceptor interface to audit changes to entity objects in a web app. Part of the audit data recorded is the before and after value of specific columns on an update. This interceptor callback mechanism works fine for objects that are updated in the same Hibernate Session that they were retrieved in - I have access to the previous and current state of the object on the update. But for objects that were retrieved with a session during a prior http request and updated with a different session on a subsequent http request, the previous state is unavailable. What I'd like to be able to do during the update http request is associate the previously retrieved object with a new Hibernate Session and have that session use the state of the object when it was associated with the session as the previous state. That way, the previous state would be available on the interceptor callback during the update.

Something like this:


SomeObject o = request.getSession().getAttribute("someobject");
// obtain a new hibernate session
Session hibernateSession = ....
hibernateSession.associate(o); // new method call
...
o.setFoo(newFoo);
o.setBar(newBar);
...
hibernateSession.update(o);
hibernateSession.flush();
hibernateSesion.connection().commit();

Does a method on the session object exist to do what associate() would do? I was thinking I could do an update(), but it still seemed the previous state was not available in the interceptor callback.

TIA
-Jay


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 03, 2003 5:42 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
In Hibernate 2.1 you can use session.lock() for this.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 03, 2003 10:36 pm 
Beginner
Beginner

Joined: Tue Sep 02, 2003 9:28 pm
Posts: 25
Thanks - I tried it with 2.1 beta2 and worked great.

-Jay


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.