Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » get original Object state from Session
get original Object state from Session [message #554752] Tue, 24 August 2010 10:46 Go to next message
Radu  is currently offline Radu Friend
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 14:09 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
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 : Twitter
Re: get original Object state from Session [message #555423 is a reply to message #555405] Thu, 26 August 2010 14:33 Go to previous messageGo to next message
Radu  is currently offline Radu Friend
Messages: 12
Registered: August 2010
Junior Member
Thanks for reply James!

There is any way to get the old value from the set of changes?
I see the method getNewValue(), but there is no getOldValue() method.

This is why I need the backup clone, so I can retrieve the original value for the changed attributes.
Re: get original Object state from Session [message #556004 is a reply to message #554752] Mon, 30 August 2010 14:14 Go to previous message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

The change set does not currently store the old value. Please log a bug for this and vote for it.

Currently you would need to track the old value yourself, or switch to deferred change tracking to be able to access the backup clone.


James : Wiki : Book : Blog : Twitter
Previous Topic:switch to session.xml
Next Topic:Problem with DB2
Goto Forum:
  


Current Time: Fri Dec 19 03:19:00 GMT 2014

Powered by FUDForum. Page generated in 0.02233 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software