views:

70

answers:

1

Hi there,

lets take this example

<class name="Product">
<id name="serialNumber" column="productSerialNumber"/>
<property name="category" column="category" />
<set name="categories">
    <key column="productSerialNumber_FK" not-null="true"/>
    <one-to-many class="Part"/>
</set>

The collection mapping always maps with the id from the class, which holds the foreign key. Is it possible to let hibernate map the collection through an other property/column? So that in this example category is mapped against the class Part?

+1  A: 

Check out the property-ref attribute. You can use the property-ref attribute in one-to-one many-to-one mappings. (That is, the other 'end' of the relationship).

However, in your example, you display a 'set', where you can specify the 'key column'. Though I see that you've specified a foreign-key name there, you can also specify the columnname.

Frederik Gheysels
Do you know whether this is also possible with annotations?
Willi