开发者

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 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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜