-->
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.  [ 6 posts ] 
Author Message
 Post subject: One to many foreign key on non-primary key
PostPosted: Mon Jul 26, 2004 5:30 pm 
Beginner
Beginner

Joined: Wed Jul 14, 2004 11:51 am
Posts: 43
Hello,

I have to map my hibernate classes to an existing db and am having the following problem:

I have ClassA which has a one-to-many relationship with ClassB. However the foreign key is not done with the primary key of class A.

The data model would look like this

Code:
Table A
---------
field1 (primary key)
field2

Table B
---------
field3 (primary key)
field4


In Table B, field 4 is a foreign key to field2 (I know this is a bad practice for it should be mapped to field1 but as I said it is an existing database).

Therefore, what I am trying to do is set the correct hibernate mapping to be able to specify the property (or field) of the foreign key (which is not the primary key). I saw that this is possible for a many-to-one relationship with the attribute property-ref:
Code:
<many-to-one
        name="propertyName"                                (1)
        column="column_name"                               (2)
        class="ClassName"                                  (3)
        cascade="all|none|save-update|delete"              (4)
        outer-join="true|false|auto"                       (5)
        update="true|false"                                (6)
        insert="true|false"                                (6)
        property-ref="propertyNameFromAssociatedClass"     (7)
        access="field|property|ClassName"                  (8)
/>



Unfortunately, I can't find the equivalent for a Set and a one-to-many collection.

Anybody have an idea how I could do this (if I can) or if this is a know feature upcoming?

Thanks,

Francois


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 27, 2004 12:19 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
You can't and I don't thnk we'll support such features in the future

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 28, 2004 10:35 am 
Beginner
Beginner

Joined: Wed Jul 14, 2004 11:51 am
Posts: 43
Hmmm.... I can understand that it might not be implemented yet but I found it weird for it not to be in future plans. I understand that it is a bad practice to map a foreign key on a non-primary key but unfortunately many legacy sytems use such associations. Therefore to be able to map hibernate on these entities it is necessary to have this.

Anyway, if I have a little time, I might try to work on it myself.

Thanks for your reply,

Fran


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 30, 2004 9:53 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Atually if you have such issues in you relational model, this probably means that you DB model will be quite hard to use with an ORM (other mistakes etc...)

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 04, 2005 4:15 pm 
Newbie

Joined: Thu Nov 04, 2004 1:37 pm
Posts: 10
this seems odd to me. i realize it is not normal to form a relationship on something other than the primary key, but it is common and often people will form relationships on alternate or unique keys.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 05, 2005 4:40 am 
Newbie

Joined: Mon Jan 03, 2005 5:21 am
Posts: 2
I find it bit odd tooo. In fact I'm facing the same problem which I have posted little earlier today.


[url]
http://forum.hibernate.org/viewtopic.php?t=937533
[/url]

_________________
-------
Kasun.


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