IntelliJ Java IDE
The moose likes Object Relational Mapping and the fly likes Natural id spanning multiple persistent classes? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Object Relational Mapping
Reply Bookmark "Natural id spanning multiple persistent classes?" Watch "Natural id spanning multiple persistent classes?" New topic
Author

Natural id spanning multiple persistent classes?

aravind yarram
Greenhorn

Joined: Mar 28, 2003
Posts: 12
Hi all,

I've a situation where my business key is a combination of properties of two persistent entities. I am not sure how to use the "natural-id" element to group them. Following should be my business key

csaType + csaStartDate + csaEndDate + serialNumber (from Equipment.hbm.xml)

I appreciate your help. Thank you in advance!

Hibernate version: 3.x

Mapping documents:

Csa.hbm.xml

<class name="Csa" table="CSA">
<id name="id" column="CSA_ID">
<generator class="native"/>
</id>
<property name="csaType" column="CSA_TYPE" type="string" not-null="true" length="2"/>
<property name="detailedCsaType" column="CSA_TYPE_DETAIL" type="string" not-null="true" length="20"/>
<property name="startingSmu" column="STARTING_SMU" type="double" not-null="true" precision="10" scale="2"/>
<property name="smuIndicator" column="SMU_INDICATOR" type="string" not-null="true" length="2"/>
<property name="equipmentDeliveryDate" column="EQUIP_DELIVERY_DATE" type="date" not-null="true" />
<property name="csaStartDate" column="CSA_START_DATE" type="date" not-null="true" />
<property name="csaEndDate" column="CSA_END_DATE" type="date" not-null="true" />
<component name="csaSourceInfo" class="CsaSource">
<property name="dealerCode" column="DEALER_CODE" type="string" not-null="true" length="6"/>
<property name="regionCode" column="REGION_CODE" type="string" not-null="true" length="5"/>
</component>
<component name="csaAuditInfo" class="AuditInfo">
<property name="enteredDate" column="ENTERED_DATE" type="date" not-null="true" />
<property name="committer" column="COMMITTER" type="string" not-null="true" length="10"/>
<property name="modifiedDate" column="MODIFIED_DATE" type="date" not-null="true" />
</component>
<many-to-one name="equipment" class="Equipment" column="FK_EQUIP_ID" cascade="all" unique="true"/>
</class>

Equipment.hbl.xml

<class name="Equipment" table="EQUIPMENT">
<id name="id" column="EQUIP_ID">
<generator class="native" />
</id>
<property name="equipmentType" column="EQUIP_TYPE" type="string" not-null="true" length="2"/>
<property name="serialNumber" column="SERIAL_NUM" type="string" not-null="true" length="20"/>
<property name="model" column="MODEL" type="string" not-null="true" length="10"/>
<property name="industryCode" column="INDUSTRY_CODE" type="string" not-null="true" length="2"/>
<property name="mode" column="MODES" type="string" not-null="true" length="1"/>
<one-to-one name="owningCsa" class="Csa" property-ref="equipment"/>
</class>

Name and version of the database you are using racle 10g


SCJP2<br />BEA Certified J2EE Developer
 
 
subject: Natural id spanning multiple persistent classes?
 
Threads others viewed
ORA-00001: unique constraint exception
Unique constraint on multiple columns (combined)
Help with mappings in Hibernate
Hibernate Issue
Hibernate Querys.
MyEclipse, The Clear Choice