In the Hibernate we found an ordinary association to another persistent class is declared using a many to many element. In this relational model we used a many to many association. In this association we use a foreign key is one table is referencing the primary key column of the target table.
<many-to-one
name="propertyName"
column="column_name"
class="ClassName"
cascade="cascade_style"
fetch="join|select"
update="true|false"
insert="true|false"
property-ref="propertyNameFromAssociatedClass"
access="field|property|ClassName"
unique="true|false"
not-null="true|false"
optimistic-lock="true|false"
lazy="proxy|no-proxy|false"
not-found="ignore|exception"
entity-name="EntityName"
formula="arbitrary SQL expression"
node="element-name|@attribute-name|element/@attribute|." embed-xml="true|false" index="index_name" unique_key="unique_key_id" foreign-key="foreign_key_name"
/>
Property |
Description |
name(optional) |
Here we use the foreign key column. This can also be specified by nested <column> element. |
class(optional) |
It defaults set on the property type determined by reflection. The name of the associated class. |
cascade(optional) |
It specifies which operations should be cascaded from the parent object to the associated object. |
fetch(optional) |
Defaults set on select. Here we need to chooses between outer-join fetching or sequential select fetching. |
update,insert(optional) |
It sets on by default on the true. It sepecifies that the mapped columns should be included in SQL UPDATE and INSERT satatement. Setting both to false allows a pure “derived†association whose value is initialized from another property that maps to the same column or by a trigger or other application. |
property-ref(optional) |
The name of a property of the associated class that is joined to this foregin key. If not specified, the primary key of the associated class is used. |
access(optional) |
We found it by defaults on property. The strategy hibernae uses for accessing the property value. |
unique(optional) |
It enables the DDL generations of a unique constraint for the foregin-key column. By allowing this to be the target of a property-ref, with this we can make the association multiplicity one to one. |
not-null(optional) |
It enables the DDL generation of a nullability constraint for the foreign key columns. |
optimistic-lock(optional) |
It defaults to true. It sepcifies that updates to this property do or do not require acquistion of the optimistic lock. In other word we can it determines if a version increment should occur when this property is dirty. |
lazy(optional) |
Defaults on proxy. We found by defaults, single point associations are proxied. lazy=â€no-proxy†specifies that property should be fetched lazily when the instance variable is first accessed. This requires build time bytecode instrumentation. lazy=â€false†specifies that the association will always be eagerly fetched. |
Not-found(optional) |
We found this by defaults to exception. It specifies how foreign key that reference missing rows will be handled. So we need to ignore will treat a missing row as a null association. |
entity-name(optional) |
This entity name of the associated class. |
formula(optional) |
An SQL exception that defines the value for a computed foreign key. |