A
one-to-one association to another persistent
class is declared using a one-to-one element.
.
| <one-to-one |
| |
name="propertyName" (1)
class="ClassName" (2)
cascade="cascade_style"
(3)
constrained="true|false"
(4)
fetch="join|select" (5)
property-ref="propertyNameFromAssociatedClass"
(6)
access="field|property|ClassName"
(7)
formula="any SQL expression"
(8)
entity-name="EntityName"
|
(1)
(2)
(3)
(4)
(5)
(6)
(7)
(8)
|
| /> |
| (1) |
name:
The name of the property. |
| (2) |
class
(optional - defaults to the property
type determined by reflection): The
name of the associated class. |
| (3) |
cascade
(optional) specifies which operations
should be cascaded from the parent
object to the associated object. |
| (4) |
constrained
(optional) specifies that a foreign
key constraint on the primary key
of the mapped table references the
table of the associated class. This
option affects the order in which
save() and delete() are cascaded,
and determines whether the association
may be proxied (it is also used by
the schema export tool). |
| (5) |
fetch
(optional - defaults to select): Chooses
between outer-join fetching or sequential
select fetching. |
| (6) |
property-ref:
(optional) The name of a property
of the associated class that is joined
to the primary key of this class.
If not specified, the primary key
of the associated class is used. |
| (7) |
access
(optional - defaults to property):
The strategy Hibernate should use
for accessing the property value.
|
| (8) |
formula
(optional): Almost all one to one
associations map to the primary key
of the owning entity. In the rare
case that this is not the case, you
may specify a some other column, columns
or expression to join on using an
SQL formula. (See org.hibernate.test.onetooneformula
for an example.) |
A typical many-to-one declaration looks
as simple as this:
| <many-to-one
name="product" class="Product"
column="PRODUCT_ID"/>
|
|