onigunn
onigunn

Reputation: 4778

Hibernate mapping collection by column

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?

Upvotes: 0

Views: 758

Answers (1)

Frederik Gheysels
Frederik Gheysels

Reputation: 56934

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.

Upvotes: 1

Related Questions