• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

<join>: <key>: different composite key

 
Sandeep Vaid
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have Bond domain class which maps to 2 tables viz. BOND nad BONDBASIC. The composite-key of both these tables are different.

BOND -----> INVESTMENTID, USECODE, STARTTIME (as composite-key)
BONDBASIC ----> INVESTMENTID, INVESTMENTID2, STARTTIME, TYPE (as composite-key)

NOTE: This is a legacy database, which i cannot change..

In bond.hbm.xml:

<class name="BondBO" table="TBINVESTMENTPERIOD" optimistic-lock="version" >
<composite-id name="compBondBO" class="CompBondBO">
<key-property name="investmentId" column="INVESTMENTID"/>
<key-property name="useCode" column="USECODE"/>
<key-property name="startTime" column="STARTTIME"/>
</composite-id>

<version unsaved-value="undefined" name="version" column="VERSION" type="com.tietoenator.lis.common.db.Db2Timestamp" />

<join table="BONDBASIC">
<key>
<!-- <column name="INVESTMENTID"></column>-->
<!-- <column name="STARTTIMESTAMP"></column>-->
</key>
</join>
</class>

How to specify the FK and PK of BONDBASIC ?
 
Sandeep Vaid
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Supose i change the above association as:

<class name="BondBO" table="BOND" optimistic-lock="version" >
<composite-id>
<key-property name="investmentId" column="INVESTMENTID"/>
<key-property name="useCode" column="USECODE"/>
<key-property name="startTime" column="STARTTIME"/>
</composite-id>

<properties name="BasicRef">
<property name="investmentId" column="INVESTMENTID" insert="false" update="false"></property>
<property name="startTime" column="STARTTIME" insert="false" update="false"></property>
</properties>

<version unsaved-value="undefined" name="version" column="VERSION" type="com.tietoenator.lis.common.db.Db2Timestamp" />

<join table="BONDBASIC">
<key property-ref="BasicRef"/>
</join>
</class>

when i try to save BondBo, It gives me that error that
org.hibernate.MappingException: Foreign key (FKE209E91BE94636B:PRODUCTBASIC [BondBo])) must have same number of columns as the referenced primary key (BOND [INVESTMENTID,USECODE,STARTTIME])

This limitation even with property-ref seems incorrect. Moreover there is no way to define the composite-id for BONDBASIC.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic