| ObjectChangeSet always null [message #555708] |
Fri, 27 August 2010 14:03  |
Radu Messages: 12 Registered: August 2010 |
Junior Member |
|
|
Hi All,
I need to get object changed set before calling entityManager merge() method, so before the transaction is committed.
I always get null when calling getObjectChangeSetForClone(objectToBeUpdated).
The code I'm using is:
JpaEntityManager jpaEntityManager = (JpaEntityManager)em.getDelegate();
UnitOfWorkChangeSet changeSet = (UnitOfWorkChangeSet)jpaEntityManager.getUnitOfWork().getCur rentChanges();
ObjectChangeSet objChangedSet = changeSet.getObjectChangeSetForClone(objectToBeUpdated);
objChangedSet is null no meter if the objectToBeUpdated is dirty or not.
There is any additional configuration property I have to add in persistence.xml to get this working?
How can I get the object change set without extending DescriptorEventAdapter?
Thanks!
|
|
|
| Re: ObjectChangeSet always null [message #556072 is a reply to message #555708] |
Mon, 30 August 2010 13:34   |
James Sutherland Messages: 1834 Registered: July 2009 |
Senior Member |
|
|
What is objectToBeUpdated, is it the object you want to merge, or the object in the persistence context? You must use the object from the persistence context (i.e. em.find(objectToBeUpdated.getClass(), objectToBeUpdated.getId()))
getObjectChangeSetForClone() will return the current changes for the object in the persistence conext, if you have not merge yet, then there will not be any changes.
James : Wiki : Book : Blog
|
|
|
|
| Re: ObjectChangeSet always null [message #556723 is a reply to message #555708] |
Thu, 02 September 2010 09:02  |
James Sutherland Messages: 1834 Registered: July 2009 |
Senior Member |
|
|
getCurrentChanges() will return all changes made in the persistence unit.
getObjectChangeSetForClone() will only return the local object's change (if any), it will include any changes to any mapped attribute (basic, 1-1, 1-m, embedded, etc.). If the relationship did not change (i.e. added/removed, different object) then there will be no change for the relationship, even if the target of the relationship changed. The targets changes will be in their own change set.
So you will need to look up the change sets for the related objects to see if they changed.
James : Wiki : Book : Blog
|
|
|
Powered by
FUDForum. Page generated in 0.01591 seconds