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


Use @VariableOneToOne to represent a pointer references between a java object and an implementer of an interface. This mapping is usually represented by a single pointer (stored in an instance variable) between the source and target objects. In the relational database tables, these mappings are normally implemented using a foreign key and a type code.

Annotation Elements

Table 2-78 describes this annotation's elements.

Table 2-78 @VariableOneToOne Annotation Elements

Annotation Element Description Default


(Optional) Array of operations that must be cascaded to the target of the association.


(Optional) Array of discriminator types that can be used with this mapping.

If none are specified, EclipseLink adds entities within the persistence unit that implement the target interface.

If DiscriminatorColumn is STRING, EclipseLink uses

If DiscriminatorColumn is CHAR, EclipseLink uses the first letter of the entity class.

If DiscriminatorColumn is INTEGER, EclipseLink uses the next integer after the highest integer explicitly stated.


(Optional) The discriminator column that contains the type identifiers.



(Optional) Specify how the value of the field or property should be loaded:

  • Eager: Requires that the persistence provider runtime must eagerly fetch the value

  • Lazy: Hints that the persistence provider should lazily load the value



(Optional) Specify if the association is optional.


(Optional) Specify if interface class that is the target of this mapping.


(Optional) The interface class that is the target of this mapping.

If none is specified, EclipseLink will infer the interface class based on the type of object being referenced.


You can specify @VariableOneToOne on an Entity, MappedSuperclass, or Embeddable class.


Example 2-124 shows how to use the @VariableOneToOne annotation.

Example 2-124 Using @VariableOneToOne Annotation

        @DiscriminatorClass(discriminator="E", value="Email.class"), 
        @DiscriminatorClass(discriminator="P", value="Phone.class")
@JoinColumn(name="CONTACT_ID", referencedColumnName="C_ID")
public Contact getContact() {
    return contact;

Example 2-125 shows the same mapping using the <variable-one-to-one> XML element in the eclipselink-orm.xml file.

Example 2-125 Using <variable-one-to-one> XML

<variable-one-to-one name="contact" fetch="LAZY">
    <discriminator-column name="CONTACT_TYPE"/>
    <discriminator-class discriminator="E" value="Email.class"/>
    <discriminator-class discriminator="P" value="Phone.class"/>
    <join-column name="CONTACT_ID" referenced-column-name="C_ID"/>

See Also

For more information, see: