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.  [ 7 posts ] 
Author Message
 Post subject: joining two tables with non-Primary key attributes
PostPosted: Thu May 10, 2007 7:40 am 
Newbie

Joined: Thu Jan 04, 2007 2:18 am
Posts: 4
Hi!
I have Table A with attributes A1(PK), A2, A3

I have another table B with attributes B1(PK), B2 and B3

now, I need to join table A and B on the basis of A3 = B3.

Can you tell me how to do it in hibernate xml file using join.
The problem is that how to specify which column of Table A to be mapped on which Column of Table B in the mapping file where both column are not primary keys.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 10, 2007 7:56 am 
Regular
Regular

Joined: Mon Mar 26, 2007 12:38 am
Posts: 119
Hi,
Here is one way of getting it done.
I have set up a unidirectional association from A to B.

<class name="A" table="a">
<id name="id" column="a1"></id>
<property name="a2" />
<many-to-one name="product" property-ref="b3" fetch="join" lazy="false" >
<formula>a3</formula>
</many-to-one>
</class>

<class name="B" table="b">
<id name="id" column="b1" ></id>
<property name="b2" />
<property name="b3" />
</class>


This results in,
a.a3 = b.b3 (+)

--------------------------------------------
Rate the reply if you find it helpful


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 10, 2007 8:24 am 
Newbie

Joined: Thu Jan 04, 2007 2:18 am
Posts: 4
Thanks!

It worked for me.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 08, 2007 10:05 am 
Newbie

Joined: Wed Jun 28, 2006 10:39 pm
Posts: 2
How to do that with Hibernate-annotations ? I didnt find any "property-ref" available. The only annotation is @JoinColumn(referencedColumnName), but that does not work when a column is mapped as a ManyToOne association.


Top
 Profile  
 
 Post subject: how about with annotations
PostPosted: Sun Jun 10, 2007 12:30 am 
Newbie

Joined: Tue Jun 05, 2007 12:52 am
Posts: 2
is it possible to accomplish the same thing w/annotations?


Top
 Profile  
 
 Post subject: how about with annotations
PostPosted: Sun Jun 10, 2007 12:30 am 
Newbie

Joined: Tue Jun 05, 2007 12:52 am
Posts: 2
is it possible to accomplish the same thing w/annotations?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 10, 2007 1:17 pm 
Newbie

Joined: Wed Mar 22, 2006 9:02 am
Posts: 7
I tried using @JoinColumns, but I still need to specify @Column for each relationship (they must be set as insertable=false and updatable=false) and worked for me.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.