Hi,
I'm trying to map a table having a composite key wich contains a foreign key on a table where the key is itself a composite key. Here is the mapping.
Code:
<hibernate-mapping>
<class
name="com.atronicsystems.database.data.OnlineCollectionSchedule"
table="SCOLPLA"
dynamic-update="false"
dynamic-insert="false"
>
<composite-id name="id" class="com.atronicsystems.database.data.OnlineCollectionScheduleId"
>
<key-property
name="weekDay"
type="java.lang.Integer"
column="JOUR"
length="1"
/>
<key-many-to-one
name="onlineCollectionDescription" class="com.atronicsystems.database.data.OnlineCollectionDescription"
column="onlineCollectionDescription"
/>
</composite-id>
...
</hibernate-mapping>
<hibernate-mapping>
<class
name="com.atronicsystems.database.data.OnlineCollectionDescription"
table="SCOLLEC"
dynamic-update="false"
dynamic-insert="false"
>
<composite-id
name="id" class="com.atronicsystems.database.data.OnlineCollectionDescriptionId"
>
<key-property
name="companyCode"
type="java.lang.String"
column="COD_SOCIET"
/>
<key-property
name="casinoCode"
type="java.lang.String"
column="COD_ETABLI"
/>
<key-property
name="collectIdentifier"
type="java.lang.Long"
column="ID_COLLECT"
/>
</composite-id>
...
</hibernate-mapping>
The problem is that with this mapping i got the following error:
Code:
Error was
net.sf.hibernate.MappingException: Foreign key (SCOLPLA [COD_SOCIET])) must have same number of columns as the referenced primary key (SCOLLEC [COD_SOCIET,COD_ETABLI,ID_COLLECT])
It seems logic because OnlineCollectionDescription does not contains variables of many to one association.
But if i change the many-to-one association and i use an OnlineCollectionDescriptionId rather than a OnlineCollectionDescription class to map the FK. The error is :
Code:
An association from the table SCOLPLA refers to an unmapped class: com.atronicsystems.database.data.OnlineCollectionDescriptionId
So how can i define a composite key which contains a foreign key defined by itself by a composite key?