-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: CompositeID Query..
PostPosted: Tue May 16, 2006 7:05 am 
Newbie

Joined: Fri Apr 28, 2006 6:14 am
Posts: 8
Hi All,

I have a table [Trading Partners]


BOMID -- PK
ID -- PK

TradingPartnerType
PartnerID -- PK
CompanyName1
CompanyName2
Street
HouseNumber
City
PostalCode
Country


Is the following TradingPartner.hbm.xml is correct??

<class name="TradingPartner" table="TradingPartner">
<!--
<key column="id"/> IS THIS REQUIRED..
-->
<composite-id>
<key-property name="BOMID "/>
<key-property name="KEY_ID"/>
<key-property name="TradingPartnerType"/>
<key-property name="PartnerID "/>
<key-property name="CompanyName1"/>
<key-property name="KEY_CompanyName2"/>
<key-property name="Street"/>
<key-property name="HouseNumber"/>
<key-property name="City"/>
<key-property name="PostalCode"/>
<key-property name="Country"/>
</composite-id>
</class>

Please correct me, if i somthing is missing..

Also is it necessary to have <id> element in .hbm.xml file..

<id name="id" column="uid" type="long">
<generator class="hilo"/>
</id>

I may not need a column, which is auto generated..

If its there, how can i give my own value, [unique key which i would want to generate/set] & not hibernate's <generator> node.

All the required values for each of the column will be set in code/application..

Any help would be highly appreciated..
Thanks in Advance.
/Shridhar..


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 16, 2006 8:12 am 
Expert
Expert

Joined: Tue Apr 25, 2006 12:04 pm
Posts: 260
your composite_id should include only 3 columns. Also there is no need for <key column='id'> element.

Code:
<composite-id>
   <key-property name="bomID" column="BOMID"/>
   <key-property name="id" column="ID"/>
   <key-property name="partnerID" column="PartnerID"/>
</composite-id>


remaining columns, you could just add as normal <property>'s


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 16, 2006 11:25 pm 
Newbie

Joined: Fri Apr 28, 2006 6:14 am
Posts: 8
Hi,
Thanks for your reply..

I have 2 tables, both having composite keys..
The relation is 1 --> N
BOMDETAILS [1] --> TradingPartners [N]


BOMDETAILS

BOMID -- PK
PartnerID -- PK

BOMName
OrderNumber
QuoteNumber
EnquiryNumber
BOMStatus
BOMCreatedDate

TradingPartners

BOMID -- PK
ID -- PK

TradingPartnerType
PartnerID -- PK
CompanyName1
CompanyName2
Street
HouseNumber
City
PostalCode
Country


Are the foloowing mappings correct//

<composite-id>
<key-property name="bomID" column="BOMID"/>
<key-property name="partnerID" column="PartnerID"/>
</composite-id>

<set name="TP" cascade="all" lazy="true">
<key column="bomID"/>
<one-to-many class="com.test.TradingPartner"/>
</set>


& all <property/> fields

<composite-id>
<key-property name="bomID" column="BOMID"/>
<key-property name="ID" column="ID"/>
</composite-id>

<many-to-one name="bom" class="com.test.BOMDets" column="bomID"/>

& all <property/> fields..

Its like this, 2 are 2 tables, with composite keys in each table, they have 1 --> N relation ship, when i enter the values, i would be paasing it thru the appln.[NO <generator/>] , when i want to fetch the values, i will pass the bomIB to the BOMDetails class, which would internally [mapping] fetch all the [N] Trading partners..

Are the mapping correct? pls correct me, if i am wrong..

Thanks,
/Shridhar..


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 16, 2006 11:33 pm 
Expert
Expert

Joined: Tue Apr 25, 2006 12:04 pm
Posts: 260
everything looks good in your mapping files except many-to-one element

put that element as

<many-to-one name="bom" class="com.test.BOMDets" column="bomID" insert="false" update="false"/>

Also on the set element, try to have inverse="true" for bi-directional relationships


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.