Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:
3.0.5
I’m currently working with a legacy database. As you can see I have a person and an issue that are joined with a many to many relationship. The many to many table has some extra columns that I need to persist and return. I attempted to use a composite-id with key-many-to-one associations, but the key-many-to-one associations do not support cascading. If I define this set as an idbag (as suggested by the complex issue FAQ), it is possible to do so without duplicating all the column definitions and only changing the key values for the person and issue idbag definitions? See below for my current mapping and a clearer illustration of the issue. Thanks in advance for the help.
Todd
Mapping documents:
Person
Code:
<hibernate-mapping>
<class name="com.ata.cats.dataacess.value.PersonVo" table="PAX">
<id name="id" type="java.lang.Long" unsaved-value="null">
<column name="PAX_ID" precision="9" scale="1" />
<generator class="sequence">
<param name="sequence">SEQ_CAT_PAX</param>
</generator>
</id>
...properties...
<set name="issuePersons" inverse="true"
cascade="all-delete-orphan">
<key column="pax_id" />
<one-to-many
class="com.ata.cats.dataacess.value.IssuePersonVo" />
</set>
</class>
</hibernate-mapping>
PersonIssueVo
Code:
hibernate-mapping>
<class name="com.ata.cats.dataacess.value.IssuePersonVo"
table="ISSUE_PAX">
<composite-id>
<key-many-to-one name="person"
class="com.ata.cats.dataacess.value.PersonVo" column="pax_id"/>
<key-many-to-one name="issue"
class="com.ata.cats.dataacess.value.IssueVo" column="issue_id" />
</composite-id>
<property name="reservationNumber" type="string">
<column name="res_nbr" length="12" />
</property>
...other properties ...
</class>
</hibernate-mapping>
Issue
Code:
<hibernate-mapping>
<class name="com.ata.cats.dataacess.value.IssueVo" table="ISSUE">
<id name="id" type="java.lang.Long" unsaved-value="null">
<column name="ISSUE_ID" precision="9" scale="1" />
<generator class="sequence">
<param name="sequence">SEQ_CAT_ISSUE</param>
</generator>
</id>
<property name="version" type="java.lang.Character">
<column name="U_VERSION" length="1" />
</property>
...properties...
<set name="issuePersons" inverse="true"
cascade="all-delete-orphan">
<key column="issue_id" />
<one-to-many
class="com.ata.cats.dataacess.value.IssuePersonVo" />
</set>
</class>
Name and version of the database you are using:
Oracle 8