|get original Object state from Session [message #554752]
||Tue, 24 August 2010 06:46
Registered: August 2010
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.
|Re: get original Object state from Session [message #555405 is a reply to message #554752]
||Thu, 26 August 2010 10:09
| James Sutherland
Registered: July 2009
Location: Ottawa, Canada
To get the object in the Session cache (current committed state, not necessarily original state), use,|
or if a UnitOfWork,
To get the changes for an object use,
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 : Twitter
Powered by FUDForum
. Page generated in 0.07331 seconds