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