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
|