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 If If |
|
(Optional) The discriminator column that contains the type identifiers. |
|
|
(Optional) Specify how the value of the field or property should be loaded:
|
|
|
(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. |
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: