-->
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: unidirectional one-to-many, but don't use pk
PostPosted: Wed Aug 16, 2006 8:40 am 
Newbie

Joined: Wed Aug 16, 2006 8:21 am
Posts: 1
Location: Munich, Germany
Hallo,

I have the following situation:
table1{a:String PK, b:string, c:string}
table2{a:string PK, b:string PK, c:string}

What I need ist an association like this:
table1.b = table2.b

When you look at it unidirectional, it is a one-to-may relationship.

What is my problem?
I don't know how to tell hibernate, that it should use the column b in table1 for the join. As far as my experience goes, hibernte always uses the primary key.

At the moment I use this:

<bag name="historicalDates" table="table2" >
<key column="b"/>
<one-to-many class="table2" />
</bag>

That is a join table1.a = table2.b and that's not what I need.

If I would use a many-to-many associoation, I would need a mapping table, right?

I am sure I am not the only one who want's to make a join like this, although it means not to have a perfect data model.

Thank you for any help!


Top
 Profile  
 
 Post subject: did u find the answer?
PostPosted: Thu Sep 21, 2006 6:13 am 
Newbie

Joined: Thu Sep 21, 2006 6:08 am
Posts: 2
Hello there,

I am having exactly the same problem. Did you find any solution or can u point me somewhere.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 21, 2006 7:15 am 
Newbie

Joined: Thu Sep 14, 2006 10:04 am
Posts: 2
Hei schneidj

I had the almost the same problem a few days ago. The solution is pretty simple:

In your mapping edit this line:
<key column="b"/> and change it to <key column="b" property-ref="b"/>

This tells hibernate to use b of table1. But you have to map b first even if you don't need it in your POJO.

Hope this helps you.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 21, 2006 8:23 am 
Newbie

Joined: Thu Sep 21, 2006 6:08 am
Posts: 2
Hi qsi,

Thank you very much for your quick answer!!


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.