Presently there is no way in hibernate using which we can specify one-to-one relationship with property-ref to part of composite-id
of another entity. The following scenario will clarify the above statement.
There is a one-to-one relationship between Product and ProductBasic.
Product -----> productId (PK)
ProductBasic ----> pId, useCode, StartTime (as composite key) and pId is also foreign key referencing Product.
This is a legacy database. We get one-to-one relationship by using the condition:
Product.productId=ProductBasic.pId and useCode='008' and startTime<currentTime<endTime.
In Product.hbm.xml:
<one-to-one name="productBasic" cascade="save-update" property-ref="activeProduct" constrained="true">
<formula>PRODUCTID</formula>
</one-to-one>
If my relationship is Product.productId = ProductBasic.pId, there is no way in hibernate to specify this relationship.
Moreover we cannot remap(refer to) the property of composite-id (compProductBasic.pId in current example)..
Hence i request for enhancement in hibernate to incorporate this.
I have also logged this in Hibernate JIRA. ID is HHH-4014
07/06/2009
Presently there is no way in hibernate using which we can specify one-to-one relationship with property-ref to part of composite-id
of another entity. The following scenario will clarify the above statement.
There is a one-to-one relationship between Product and ProductBasic.
Product -----> productId (PK)
ProductBasic ----> pId, useCode, StartTime (as composite key) and pId is also foreign key referencing Product.
This is a legacy database. We get one-to-one relationship by using the condition:
Product.productId=ProductBasic.pId and useCode='008' and startTime<currentTime<endTime.
In Product.hbm.xml:
<one-to-one name="productBasic" cascade="save-update" property-ref="activeProduct" constrained="true">
<formula>PRODUCTID</formula>
</one-to-one>
In ProductBasic.hbm.xml
<composite-id name="compProductBasic">
<key-property name="pId" column="PID" ></key-property>
<key-property name="useCode" column="USECODE" "></key-property>
<key-property name="startTime" column="STARTTIME" ></key-property>
</composite-id>
<properties name="activeProduct">
<property name="compProductBasic.pId" class="Product" insert="false" update="false" lazy="proxy" />
</properties>
If my relationship is Product.productId = ProductBasic.pId, there is no way in hibernate to specify this relationship.
Moreover we cannot remap(refer to) the property of composite-id (compProductBasic.pId in current example)..
Hence i request for enhancement in hibernate to incorporate this.
I have also logged this in Hibernate JIRA. ID is HHH-4014