Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] Weaving changes behavior of change tracking

Dear EclipseLink developers,

during my tests with static weaving, I'm seeing a significant difference in change tracking depending whether weaving is enabled or not. I'm using EclipseLink 2.6.1 (however, this issue can be seen in earlier releases, too).

I call uow.getCurrentChanges() to get all changes in current UnitOfWork and use its result to issue further database changes.

Issue summary:
With disabled weaving, EclipseLink will invoke session.getDatasourcePlatform().convertObject before comparing values With enabled weaving, EclipseLink is just using equals() without converting it beforehand.


This can be easily reproduced, I'm using Oracle database 11g (which might play a role) and static weaving:

Consider an entity A, containing a (non-PK) field (with corresponding getter/setter)):

  @Column(name = "EXT_SYS_DATE")
  @Temporal(TemporalType.DATE)
  @Basic(optional = true)
  private java.util.Date        extSysDate_;


On the database side, this field corresponds to a DATE column type (which has a precision of seconds)


Now do the following steps:

1) Create a new instance of A
2) Set extSysDate to a date with time information,
e.g. new java.util.Date(1383260408000) // corresponds to Fri Nov 01 00:00:08 CET 2013, please note the seconds part, which is set to 8.
3) persist this entity instance
4) commit the transaction //the database record will only contain the date part, all time information is set to 0
(which is OK because the field is annotated with TemporalType.DATE)
5) re-read the entity using em.find(PK)
6) Set extSysDate again to to a date with time information,
e.g. new java.util.Date(1383260408000) // corresponds to Fri Nov 01 00:00:08 CET 2013, please note the seconds part, which is set to 8.
7) Invoke uow.getCurrentChanges() and inspect its result


With disabled weaving, you won't get any differences (as expected), while you will with enabled weaving. The reason for this is that with disabled weaving, session.getDatasourcePlatform().convertObject() is called (truncating the time information) before invoking equals(), while with enabled weaving, the values are used as they are (and are treated non-equal)

This is quite obvious in the source:

Disabled weaving (expected behavior):
Have a look at org.eclipse.persistence.mappings.foundation.AbstractDirectMapping.compareObjectValues(Object, Object, AbstractSession) Before invoking equals() in line 445, the old/new values are converted in lines 433 and 434.

Enabled weaving:
Have a look at org.eclipse.persistence.internal.descriptors.changetracking.AttributeChangeListener, line 131
Only equals() is used to compare the old/new values


Questions:
* Is this behavior intended? If yes, why?
* Is there a workaround to ensure weaved change tracking will behave like the regular implementation?


Thank you so much!

Best regards,
Patric






Back to the top