-->
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: many-to-one mapping with unique key
PostPosted: Tue Aug 09, 2005 11:38 pm 
Newbie

Joined: Tue Aug 09, 2005 11:23 pm
Posts: 2
I have two tables:

PART
-----------------------------------------------------
PART_KEY - INT (PK)
PART_NUMBER - VARCHAR(100)
VENDOR_NUM - VARCHAR(100)

and

BOM_PART
--------------------------------------------------------
BOM_KEY - INT (PK)
VENDOR_NUM - VARCHAR(100)
VALUE - VARCHAR(100)

PK = Primary Key

I am using Hibernate2 and want to create a mapping of many-to-one in BomPart.hbm.xml such that I will have the Part matching the vendor_num of the BomPart. How can I do that.

vendor_num in Part table is not defined as primary key but is unique?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 10, 2005 1:28 am 
Newbie

Joined: Fri Jan 07, 2005 5:46 pm
Posts: 19
The example in section 6.1.14. properties in the reference documentation may help you.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 10, 2005 11:37 am 
Newbie

Joined: Tue Aug 09, 2005 11:23 pm
Posts: 2
I am using Hibernate2. Can this be accomplished with Hibernate 2?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 10, 2005 1:33 pm 
Newbie

Joined: Fri Jan 07, 2005 5:46 pm
Posts: 19
Here is the section from the H2 reference document that I think is relevant to your problem (from 5.1.10. many-to-one):

The property-ref attribute should only be used for mapping legacy data where a foreign key refers to a unique key of the associated table other than the primary key. This is an ugly relational model. For example, suppose the Product class had a unique serial number, that is not the primary key. (The unique attribute controls Hibernate's DDL generation with the SchemaExport tool.)

<property name="serialNumber" unique="true" type="string" column="SERIAL_NUMBER"/>
Then the mapping for OrderItem might use:

<many-to-one name="product" property-ref="serialNumber" column="PRODUCT_SERIAL_NUMBER"/>
This is certainly not encouraged, however.


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.