| get original Object state from Session [message #554752] |
Tue, 24 August 2010 06:46  |
Radu Messages: 12 Registered: August 2010 |
Junior Member |
|
|
Hi,
I need to get the original object state before an update() is called, by using JpaEntityManager from an EJB Interceptor.
I managed to get the original object by extending DescriptorEventAdapter, in the aboutToUpdate(DescriptorEvent event) method by using event.getOriginalObject().
The problem is that I can not inject @Resources in the DescriptorEventAdapter class and I need to perform some logic by using other helpers EJBs.
In the interceptor however, I can inject resources and get the JpaEntityManager, UnitOfWorkChangeSet and Session by using
JpaEntityManager jpaEntityManager = (JpaEntityManager)em.getDelegate();
UnitOfWorkChangeSet changeSet = (UnitOfWorkChangeSet)jpaEntityManager.getUnitOfWork().getCur rentChanges();
The QUESTION is how can I get the original object state (which is obviously stored in memory) from the current Active Session or UnitOfWork?
Any hint will be appreciated.
Thanks!
|
|
|
| Re: get original Object state from Session [message #555405 is a reply to message #554752] |
Thu, 26 August 2010 10:09   |
James Sutherland Messages: 1834 Registered: July 2009 |
Senior Member |
|
|
To get the object in the Session cache (current committed state, not necessarily original state), use,
session.readObject(object)
or if a UnitOfWork,
unitOfWork.getParent().readObject(object)
To get the changes for an object use,
unitOfWork.getCurrentChanges().getObjectChangeSetForClone(ob ject)
if you use deferred change tracking the UnitOfWork also stores a backup clone, which is the original state. If you use attribute change tracking (default with weaving), then there is no original state stored, only a set of changes.
James : Wiki : Book : Blog
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.01739 seconds