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


@VariableOneToOne

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

CascadeType

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


DiscriminatorClasses

(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 Entity.name().

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.

DiscriminatorColumn

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

DTYPE

FetchType

(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

Eager

Optional

(Optional) Specify if the association is optional.


OrphanRemoval

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


TargetInterface

(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.



Usage

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


Examples

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

Example 2-124 Using @VariableOneToOne Annotation

@VariableOneToOne(
    cascade={ALL},
    fetch=LAZY,
    discriminatorColumn=@DiscriminatorColumn(name="CONTACT_TYPE"),
    discriminatorClasses={
        @DiscriminatorClass(discriminator="E", value="Email.class"), 
        @DiscriminatorClass(discriminator="P", value="Phone.class")
    }
}
@JoinColumn(name="CONTACT_ID", referencedColumnName="C_ID")
@PrivateOwned
@JoinFetch(INNER)
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">
    <cascade>
        <cascade-all/>
    </cascade>
    <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"/>
    <private-owned/>
    <join-fetch>INNER</join-fetch>
</variable-one-to-one>


See Also

For more information, see: