Java Reference
In-Depth Information
Table 7-8. Continued
Attribute
Values
Default
Description
lazy
true , false
Overrides the entity-loading mode.
name
Assigns a name to the entity (required in dynamic
mappings).
node
Specifies the name of the XML element or attribute
that should be used by the XML relational persist-
ence features.
outer join
true , false ,
Specifies whether an outer join should be used.
auto
property-ref
Specifies the column in the target entity's table that
the foreign key references. If the referenced table's
foreign key does not reference the primary key of the
“many” end of the relationship, then property-ref
can be used to specify the column that it references.
This should only be the case for legacy designs—
when creating a new schema, your foreign keys
should always reference the primary key of the
related table.
You would select a primary key association when you do not want an additional table
column to relate the two entities. The master of the two entities takes a normal primary key
generator, and its one-to-one mapping entry will typically have the attribute name and asso-
ciated class specified only. The slave entity will be mapped similarly, but must have the
constrained attribute setting applied to ensure that the relationship is recognized.
Because the slave class's primary key must be identical to that allocated to the master, it is
given the special id generator type of foreign . On the slave end, the <id> and <one-to-one>
elements will therefore look like this:
<id name="id" column="product">
<generator class="foreign">
<param name="property">campaign</param>
</generator>
</id>
<one-to-one name="campaign"
class="com.hibernatebook.xmlmapping.Campaign"
constrained="true"/>
There are some limitations to this approach: it cannot be used on the receiving end of
a many-to-one relationship (even when the “many” end of the association is limited by a
unique constraint), and the slave entity cannot be the slave of more than one entity.
In these circumstances, you will need to declare the master end of the association as a
uniquely constrained one-to-many association. The slave entity's table will then need to take
a foreign key column associating it with the master's primary key. The property-ref attribute
setting is used to declare this relationship, like so:
Search WWH ::




Custom Search