-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Many-to-many with extra columns. idbag vs. Object
PostPosted: Wed Aug 30, 2006 10:09 pm 
Regular
Regular

Joined: Fri Feb 13, 2004 10:02 pm
Posts: 90
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.