docd indexed associations
git-svn-id: https://svn.jboss.org/repos/hibernate/trunk/Hibernate3/doc@7126 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
parent
1991e3a206
commit
dd0138f4e2
|
@ -854,8 +854,8 @@ session.persist(category); // The relationship will be saved]]></p
|
||||||
</set>
|
</set>
|
||||||
</class>
|
</class>
|
||||||
|
|
||||||
<class name="eg.Child">
|
<class name="Child">
|
||||||
<id name="id" column="id"/>
|
<id name="id" column="child_id"/>
|
||||||
....
|
....
|
||||||
<many-to-one name="parent"
|
<many-to-one name="parent"
|
||||||
class="Parent"
|
class="Parent"
|
||||||
|
@ -870,6 +870,74 @@ session.persist(category); // The relationship will be saved]]></p
|
||||||
|
|
||||||
</sect2>
|
</sect2>
|
||||||
|
|
||||||
|
<sect2 id="collections-indexedbidirectional">
|
||||||
|
<title>Bidirectional associations with indexed collections</title>
|
||||||
|
<para>
|
||||||
|
A bidirectional association where one end is represented as a <literal><list></literal>
|
||||||
|
or <literal><map></literal> requires special consideration. If there is a property of
|
||||||
|
the child class which maps to the index column, no problem, we can continue using
|
||||||
|
<literal>inverse="true"</literal> on the collection mapping:
|
||||||
|
</para>
|
||||||
|
|
||||||
|
<programlisting><![CDATA[<class name="Parent">
|
||||||
|
<id name="id" column="parent_id"/>
|
||||||
|
....
|
||||||
|
<map name="children" inverse="true">
|
||||||
|
<key column="parent_id"/>
|
||||||
|
<map-key column="name"
|
||||||
|
type="string"/>
|
||||||
|
<one-to-many class="Child"/>
|
||||||
|
</map>
|
||||||
|
</class>
|
||||||
|
|
||||||
|
<class name="Child">
|
||||||
|
<id name="id" column="child_id"/>
|
||||||
|
....
|
||||||
|
<property name="name"
|
||||||
|
not-null="true"/>
|
||||||
|
<many-to-one name="parent"
|
||||||
|
class="Parent"
|
||||||
|
column="parent_id"
|
||||||
|
not-null="true"/>
|
||||||
|
</class>]]></programlisting>
|
||||||
|
|
||||||
|
<para>
|
||||||
|
But, if there is no such property on the child class, we can't think of the association as
|
||||||
|
truly bidirectional (there is information available at one end of the association that is
|
||||||
|
not available at the other end). In this case, we can't map the collection
|
||||||
|
<literal>inverse="true"</literal>. Instead, we could use the following mapping:
|
||||||
|
</para>
|
||||||
|
|
||||||
|
<programlisting><![CDATA[<class name="Parent">
|
||||||
|
<id name="id" column="parent_id"/>
|
||||||
|
....
|
||||||
|
<map name="children">
|
||||||
|
<key column="parent_id"
|
||||||
|
not-null="true"/>
|
||||||
|
<map-key column="name"
|
||||||
|
type="string"/>
|
||||||
|
<one-to-many class="Child"/>
|
||||||
|
</map>
|
||||||
|
</class>
|
||||||
|
|
||||||
|
<class name="Child">
|
||||||
|
<id name="id" column="child_id"/>
|
||||||
|
....
|
||||||
|
<many-to-one name="parent"
|
||||||
|
class="Parent"
|
||||||
|
column="parent_id"
|
||||||
|
insert="false"
|
||||||
|
update="false"
|
||||||
|
not-null="true"/>
|
||||||
|
</class>]]></programlisting>
|
||||||
|
|
||||||
|
<para>
|
||||||
|
Note that in this mapping, the collection-valued end of the association is responsible for
|
||||||
|
updates to the foreign key.
|
||||||
|
</para>
|
||||||
|
|
||||||
|
</sect2>
|
||||||
|
|
||||||
<sect2 id="collections-ternary">
|
<sect2 id="collections-ternary">
|
||||||
<title>Ternary associations</title>
|
<title>Ternary associations</title>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue