one-to-one
A one-to-one association to another persistent class is declared using a one-to-one element.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| <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)
lazy="true|proxy|false" (9)
Hibernate 3.0.5 60
entity-name="EntityName" (10)
node="element-name|@attribute-name|element/@attribute|."
embed-xml="true|false"
foreign-key="foreign_key_name"
/> |
(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.)
(9) lazy (optional - defaults to proxy): By default, single point associations are proxied. lazy="true" specifies
that the property should be fetched lazily when the instance variable is first accessed (requires
build-time bytecode instrumentation). lazy="false" specifies that the association will always be eagerly
fetched. Note that if constrained="false", proxying is impossible and Hibernate will eager fetch the association!
Basic O/R Mapping
Extrait de Hibernate Reference
Partager