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


@InstantiationCopyPolicy

Use @InstantiationCopyPolicy to set an org.eclipse.persistence.descriptors.copying.InstantiationCopyPolicy on an Entity.


Annotation Elements

There are no elements for this annotation.


Usage

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 EclipseLink copy policy depends on your configuration:

You can specify @InstantiationCopyPolicy on an Entity, MappedSuperclass, or Embeddable entity.


Examples

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>


See Also

For more information, see: