Java Persistence API (JPA) Extensions Reference for EclipseLink, Release 2.5
  Go To Table Of Contents
 Search
 PDFComments
Comments


@ChangeTracking

Use @ChangeTracking to specify the org.eclipse.persistence.descriptors.changetracking.ObjectChangePolicy. This policy computes change sets for the EclipseLink commit process and optimizes the transaction by including objects in the change set calculation that have at least one changed attribute.


Annotation Elements

Table 2-9 describes this annotation's elements.

Table 2-9 @ChangeTracking Annotation Elements

Annotation Element Description Default

ChangeTrackingType

(Optional) The change tracking policy to use:

  • ATTRIBUTE – The object's set method is weaved to raise change events to collect changes as they are made.

    Requires usage of weaving, and LAZY collection relationships, or eager weaving.

  • OBJECT – The object's set method is weaved to mark the object as dirty. Any dirty objects are compared against a copy of their original state for changes on commit or flush operations.

    Requires usage of weaving, and LAZY collection relationships, or eager weaving.

  • DEFERRED – All managed objects are compared against a copy of their original state for changes on commit or flush.

    Does not require weaving.

  • AUTO – Does not set any change tracking policy; change tracking will be determined at runtime.

AUTO



Usage

Use this annotation to configure an alternative change policy, if the automatic policy is having issues with your application. Using @ChangeTracking may improve commit performance for objects with few attributes or objects with many changed attributes.


NoteNote:

When using change tracking with ATTRIBUTE or OBJECT, if you modify an object's field through reflection, EclipseLink will not detect the change. However, if you use DEFERRED, EclipseLink will detect the change.



Examples

Example 2-20 shows how to use @ChangeTracking to set the unit of work's change policy.

Example 2-20 Using @ChangeTracking Annotation

@ChangeTracking(DEFERRED)
@Entity
public class Employee {
    ...
}

Example 2-21 shows how to use the <change-tracking> element in the eclipselink-orm.xml file.

Example 2-21 Using <change-tracking> XML

<entity class="Employee"
    <change-tracking type="DEFERRED"/>
...
</entity>

Example 2-22 shows how to configure change tracking in the persistence unit persistence.xml file or by importing a property map.

Example 2-22 Specifying Change Tracking in persistence.xml

Using persistence.xml file:

<property name="eclipselink.weaving.changetracking" value="false"/>

Using property map:

import org.eclipse.persistence.config.PersistenceUnitProperties;
propertiesMap.put(PersistenceUnitProperties.WEAVING_CHANGE_TRACKING, "false");


See Also

For more information, see: