Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » ObjectChangeSet always null(ObjectChangeSet returns null from getObjectChangeSetForClone)
ObjectChangeSet always null [message #555708] Fri, 27 August 2010 18:03 Go to next message
Radu  is currently offline Radu Friend
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 17:34 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
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 : Twitter
Re: ObjectChangeSet always null [message #556103 is a reply to message #556072] Mon, 30 August 2010 19:20 Go to previous messageGo to next message
Radu  is currently offline Radu Friend
Messages: 12
Registered: August 2010
Junior Member
James, THANKS!

I finally got it working!

Do you know if UnitOfWorkChangeSet will reflect changes made to related objects (@ManyToOne and @OneToOne) as well?
Re: ObjectChangeSet always null [message #556723 is a reply to message #555708] Thu, 02 September 2010 13:02 Go to previous message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
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 : Twitter
Previous Topic: NullPointerException in QueryKeyExpression.getQueryKeyOrNull
Next Topic:Jpql - order by sum ???
Goto Forum:
  


Current Time: Thu Apr 25 23:28:28 GMT 2024

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

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

Back to the top