<join>: <key>: different composite key

Description

Presently hibernate doesn't support this..

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 ?
Hibernate doesn't provide any way to specify this kind of mapping..

Environment

None

Activity

Show:
Sandeep Vaid
July 7, 2009, 12:42 PM

<class name="BondBO" table="TBINVESTMENTPERIOD" optimistic-lock="version" >
should be
<class name="BondBO" table="BOND" optimistic-lock="version" >

Sandeep Vaid
July 7, 2009, 12:42 PM

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 (FKE209E91BE94636BRODUCTBASIC [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.

Assignee

Unassigned

Reporter

Sandeep Vaid

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

Affirmative

Pull Request

None

backportDecision

None

Components

Priority

Critical
Configure