-->
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> should reference NOT to the Primarykey-H
PostPosted: Mon Dec 19, 2005 9:45 am 
Newbie

Joined: Wed Sep 28, 2005 5:05 am
Posts: 11
Hi ;)
I´m using Hibernate 2.8.1 and MicrosoftSQL-Server.
My problem:
I have two tables with a one-to-many relation:

Table 1
Name: Adressen
Primary Key: __Org_RecordNo
column:Name (String36)
column:Number(int)

Table2
Name: Ansprechpartner
Primary Key: __Org_RecordNo
Foreign Key: AdressID
Column: Name(String36)

if i use the "normal" mapping the relation looks like this:
Mapping for Adressen:
...
<set inverse="true" name="AnsprechpartnerSet">
<key column ="AdressID"/>
<one-to-many class="Ansprechpartner"/>
</set>
I think that works fantastic. Now comes the PROBLEM:
The return-mapping from Ansprechpartner:
...
<many-to-one
name="Adressen"
column="AdressID"
class="Adressen"/>

That means, AdressID from Ansprechpartner references to __Org_RecordNo(PrimaryKey) from Adressen. But it have to show to the column Number of Adressen not to the primary key...a little confuse..but thats the given situation..
Ah..and it´s not allowed to me to make any changes on database...so i can just make it on mapping-file...

How can i map this?


Top
 Profile  
 
 Post subject: Re: <many-to-one> should reference NOT to the Primaryk
PostPosted: Mon Dec 19, 2005 12:31 pm 
Newbie

Joined: Wed Sep 28, 2005 5:05 am
Posts: 11
Ok...i got it...
there is a property-ref-Tag to reference to a column wich is not PrimaryKey.
Now it looks like that ;)

<set name="AnsprechpartnerSet" property-ref="Id">
<key column ="AdressID"/>
<one-to-many class="Ansprechpartner"/>
</set>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 12, 2006 6:37 am 
Regular
Regular

Joined: Wed Jun 29, 2005 11:14 pm
Posts: 119
Location: København
This doesn't work in 3.0 BTW.

<set name="AnsprechpartnerSet" property-ref="Id">
<key column ="AdressID"/>
<one-to-many class="Ansprechpartner"/>
</set>

property-ref is not allowed there. I'm trying to do a similar thing, if anyone has any suggestions.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 12, 2006 7:27 am 
Regular
Regular

Joined: Wed Jun 29, 2005 11:14 pm
Posts: 119
Location: København
Code:
<set name="AnsprechpartnerSet" >
<key column ="AdressID" property-ref="Id"/>
<one-to-many class="Ansprechpartner"/>
</set>

does work


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.