File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Object Relational Mapping and the fly likes One-to-one:property-ref to a part of composite-key Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "One-to-one:property-ref to a part of composite-key" Watch "One-to-one:property-ref to a part of composite-key" New topic

One-to-one:property-ref to a part of composite-key

Sandeep Vaid
Ranch Hand

Joined: Feb 27, 2006
Posts: 392
I have 2 classes viz. Product and ProductBasic having one-to-one relationship
Product is mapped to a table PRODUCT which has PRODUCTID as PK.
ProductBasic is mapped to a table PRODUCTBASIC which has PRODUCTID,USECODE and STARTTTIME as composite key.

My database is legacy and i cannot change it.
I get the one-to-one relationship by applying the condition as:
My database values are such that if i apply this condition i will only get once record..

In Product.hbm.xml:

<class name="Product" table="PRODUCT"
><id name="pid" type="string" column="PRODUCTID" length="10">
<generator class="assigned"></generator>

<one-to-one name="productBasic" class="ProductBasic" constrained="true" outer-join="false" cascade="save-update" property-ref="activeProductBasic" >

In ProductBasic.hbm.xml

<class name="ProductBasic" table="PRODUCTBASIC">
<composite-id name="compProductBasic" class="CompProductRelatedAssociations">
<key-property name="productId" column="PRODUCTID" type="string" length="10" />
<key-property name="useCode" column="USECODE" type="string" length="10" />
<key-property name="startTime" column="STARTTIME" type="timestamp"/>

<properties name="activeProductBasic">
<property name="compProductBasic.productId" column="PRODUCTID" type="string" length="10" insert="false" update="false"/>

but this compProductBasic.productId is giving me error...
I agree. Here's the link:
subject: One-to-one:property-ref to a part of composite-key
It's not a secret anymore!