-->
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: Table relationship
PostPosted: Thu Jan 01, 2004 5:12 am 
Newbie

Joined: Thu Jan 01, 2004 4:45 am
Posts: 4
I have a question here that I have no idea how to tackle. How do I write the hbm.xml file to implement the following relationship in hibernate?

I have 2 tables A and B.

The schema are as follows:
A {
id PK
}

B {
id_1 PK, FK
id_2 PK, FK
}

The relationship is that, B.id_1 and B.id_2 combine to form a composite id and each of them is a foreign key in table A (many-to-one).

Thanks in advance!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 01, 2004 8:04 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
If I get you right, you mean that every B has 2 As associated and every A has any numbers of Bs assoicated by id_1 and any number by id_2. If yes, this should be doable:

Use two key-many-to-one mappings for two A propertys in your mapping for class B, and use two set mappings relating to B in your mapping for class A


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 02, 2004 8:03 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
No need to have the bi-directional mapping. Only key-many-to-one inside composite-id in B.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 02, 2004 12:33 pm 
Newbie

Joined: Thu Jan 01, 2004 4:45 am
Posts: 4
Thanks for the reply. Yeah gloeglm you've got it.
I'll try to do "key-many-to-one" thing.
I'll post the result when it is done.


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.