JPA PreUpdate fired "without" changes


stephane
 

Hi,

When I update an attribute with the same value (let's say I replace with an equals value), this object is made dirty. Not a big deal, but a side effect is PreUpdate callbacks are triggered, and I don't want because no changes need to be flushed in the storage.

Ex:
em.detach(client);
client.setName(client.getName());
em.merge(client);
=> PreUpdate callback is triggered.

Looking at the statemanager, the related field (name in the example) is made dirty which I think is the reason for triggering the PreUpdate. Are there any solution to avoid making the object dirty in such situation ? Would that offend any spec to do it ? 

thanks,

--
Stephane


Andy
 
Edited

An object is not "made dirty" when setting a field to the same value ... except if the value is a floating point / double (aka imprecise) value.
NucleusJPAHelper.getObjectState(obj) defines the state at any time.


stephane
 

Hi Andy,

my issue seems related to the merge operation. I attached a junit testcase. 

thanks
--
Stephane


stephane
 
Edited

Please use this attachment.

Failing tests:
testUpdateNoChangeDetach
testUpdateNoChangeCopy

Workaround for simple situation:
testUpdateNoChangeApply

--
Stephane


Andy
 
Edited

User makes changes when an object is detached. The persistence provider is not involved in the process when the object is detached. The dirty flag is then set on ALL fields that have their setters called - read the byte code enhancement contract. When an object is "merged" the persistence provider has no original value to compare against, so just takes the dirty flags. So it updates all dirty fields.