Use @InstantiationCopyPolicy
to set an org.eclipse.persistence.descriptors.copying.InstantiationCopyPolicy
on an Entity.
There are no elements for this annotation.
The copy policy specifies how EclipseLink clones objects to and from the shared cache. With @InstantiationCopyPolicy
, in order to clone an object EclipseLink will create a new instance of the object and copy each persistent attribute. Alternative methods include @CloneCopyPolicy
, which clones the object.
Cloning is more efficient than creating a new instance and maintains transient or non-persistent attribute values. If you do not need transient or non-persistent attribute values in the shared cache, then use @InstantiationCopyPolicy
.
The default TopLink copy policy depends on your configuration:
When using weaving.internal (and field access), EclipseLink generates a specialized clone method to copy objects.
Without weaving, EclipseLink uses instantiation to copy objects.
You can specify @InstantiationCopyPolicy
on an Entity, MappedSuperclass, or Embeddable entity.
Example 2-50 shows how to use this annotation.
Example 2-50 Using @InstantiationCopyPolicy Annotation
@Entity
@InstantiationCopyPolicy
public class Employee {
...
transient List events = new ArrayList();
}
Example 2-51 shows how to use this extension in the eclipselink-orm.xml
file.
Example 2-51 Using <instantiation-copy-policy> XML
<entity name="Employee" class="org.acme.Employee" access="FIELD">
<instantiation-copy-policy/>
...
</entity>
For more information, see: