Java Reference
In-Depth Information
Listing 9.17. Unidirectional one-to-one relationship
In this listing, the User class holds a BillingInfo reference in the billingInfo
property. Because the billingInfo property holds only one instance of the
BillingInfo class , the relationship is one-to-one. The @OneToOne annotation
configures JPA to maintain this relationship in the database
.
The @OneToOne annotation, like most JPA attributes, can be used on either a class's prop-
erties or on the getter methods. The @OneToOne annotation has a few configurable prop-
erties, but they're not often used. Table 9.2 briefly describes them.
Table 9.2. Attributes of the @OneToOne annotation
Attribute
Description
Class of the object to use in the relationship. Useful if the relationships are defined by in-
terfaces and there are multiple implementing classes.
targetEntity
cascade
Database relationship changes that must be cascaded down to the related data.
fetch
Controls when the related data is populated.
optional
Specifies if the relationship is optional (see listing 9.18 ) .
Specifies the entity that owns the relationship. This element is only specified on the non-
owning side of the relationship (see listing 9.18 ) .
mappedBy
 
 
Search WWH ::




Custom Search