Java Reference
In-Depth Information
EJB 3.0 entity relationship annotations
The Java Persistence API provides metadata annotations for EJB 3.0 entity relationships.
The different types of EJB 3.0 relationships that may be defined are discussed in the
following table:
Annotation
Description
Annotation Elements
@OneToOne
Defines a single-valued
association to another entity.
The association has one-to-
one multiplicity.
targetEntity (optional): This is
the entity class that is the target of the
association.
cascade (optional): The operations that
must be cascaded to the target of the
association. By default, no operations are
cascaded.
fetch (optional): This specifies whether
the association should be lazily loaded or
eagerly fetched. The default is EAGER .
mappedBy (optional): This is the field that
owns the relationship. The mappedBy
element is specified on the non-owning
side of the relationship.
optional (optional): This specifies if the
relationship is optional. If set to false,
non-null relationships must always exist.
By default, it is true.
@OneToMany
Defines a many-valued
association with one-to-
many multiplicity.
targetEntity (optional): The entity
class that is the target of the association.
cascade (optional): This specifies the
operations that must be cascaded to the
target of the association. By default, no
operations are cascaded.
fetch (optional): This specifies the fetch
strategy. By default, it is LAZY.
mappedBy : Specifies the field that owns
the relationship. It isn't required unless
the relationship is unidirectional. In a
unidirectional relationship, only one
entity has a reference to the other. In a
bidirectional relationship, both entities
have references to each other.
Search WWH ::




Custom Search