开发者

Hibernate mapping collection by column

开发者 https://www.devze.com 2022-12-14 16:07 出处:网络
lets take this example <class name=\"Product\"> <id name=\"serialNumber\" column=\"productSerialNumber\"/>

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 ke开发者_开发问答y. 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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消