-->
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.  [ 1 post ] 
Author Message
 Post subject: Ont to many relationships foreign key
PostPosted: Wed Jul 21, 2004 5:12 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  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.