-->
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: Important info about mapping composite foreign keys missing?
PostPosted: Wed Dec 29, 2004 4:04 pm 
Newbie

Joined: Tue Dec 07, 2004 1:28 pm
Posts: 2
I went thru a mapping excercise recently and spent several hours trying to figure out why I kept getting emtpy sets when there should've been values.

When I was debugging I found that the values from the component were being bound in the wrong order to the statement.

It took me quite some time but I finally realized that they key to the set has to be mapped in the same order as the columns are mapped in the composite-id of the actual one-to-many class.

my successful attempt is included

Code:
   <class name="AcaVehicle" table="ACA_VEHICLE">
      <composite-id class="VehicleID" name="vehicleId" unsaved-value="none">
         <key-property column="C_VEHICLE_ID" name="CVehicleId" type="integer" />
         <key-property column="C_VEH_AMEND_NUM2" name="CVehAmendNum2" type="integer" />
         <key-property column="C_VEH_AMEND_NUM1" name="CVehAmendNum1" type="integer" />
         <key-property column="C_POLICY_ID" name="CPolicyId" type="integer" />
         <key-property column="C_POL_AMEND_NUM2" name="CPolAmendNum2" type="integer" />
         <key-property column="C_POL_AMEND_NUM1" name="CPolAmendNum1" type="integer" />
      </composite-id>

      <set lazy="true" order-by="C_VEHICLE_ID" name="coverages" inverse="false" cascade="save-update">
         <key >
            <column name="C_VEHICLE_ID" not-null="true" />
            <column name="C_VEH_AMEND_NUM1" not-null="true" />
            <column name="C_VEH_AMEND_NUM2" not-null="true" />
            <column name="C_POLICY_ID" not-null="true" />
            <column name="C_POL_AMEND_NUM1" not-null="true" />
            <column name="C_POL_AMEND_NUM2" not-null="true" />
         </key>
         <one-to-many class="AcaCoverage" />
      </set>
..
/************************************/

   <class name="AcaCoverage" table="ACA_COVERAGE">
      <composite-id unsaved-value="none" class="AcaCoverageId" name="AcaCoverageId">
         <key-property column="C_VEHICLE_ID" name="CVehicleId" type="integer" />
         <key-property column="C_VEH_AMEND_NUM2" name="CVehAmendNum2" type="integer" />
         <key-property column="C_VEH_AMEND_NUM1" name="CVehAmendNum1" type="integer" />
         <key-property column="C_POLICY_ID" name="CPolicyId" type="integer" />
         <key-property column="C_POL_AMEND_NUM2" name="CPolAmendNum2" type="integer" />
         <key-property column="C_POL_AMEND_NUM1" name="CPolAmendNum1" type="integer" />
         
         <key-property column="C_CVRG_AMEND_NUM2" name="CCvrgAmendNum2" type="integer" />
         <key-property column="C_CVRG_AMEND_NUM1" name="CCvrgAmendNum1" type="integer" />
         <key-property column="C_COVERAGE_ID" name="CCoverageId" type="integer" />
      </composite-id>
...


keywords: bind, order, composite, foreign, property[/i]

_________________
hibernating since 1.x


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.