[英]Composite key including foreign key in hibernate set
我不明白如何在集合中定义一个复合键,包括一个外键
这是我的对象:
MyObject MySubset
-------- -------------
String myId String subAttribute
String myAttribute String subValue
Set<MySubset> mySubset
我想要两个表MyObjectTable和MySubsetTable 。 myId是MyObjectTable的主键。 我想定义FK 身份识别码和子属性为MySubsetTable的组合键。
xml中的休眠映射是什么样的?
<hibernate-mapping>
<class table="myObjectTable" name="MyObject">
<id name="myId">
<column name="myId"/>
</id>
<property name="myAttribute"> <column name=....> </property>
<set cascade="all, delete-orphan table="MySubsetTable" name"mySubset" ...>
<!-- How should I define my key? -->
<composite-element class="MySubset">
<property name="subAttribute"> <column name="subAttribute"/> </property>
<property name="subValue"> <column name="subValue"/> </property>
</composite-element>
</set>
</class>
</hibernate-mapping>
我不使用集合而是使用地图解决了我的问题:
<hibernate-mapping>
<class table="myObjectTable" name="MyObject">
<id name="myId">
<column name="myId"/>
</id>
<property name="myAttribute"> <column name=....> </property>
<map cascade="all, delete-orphan table="MySubsetTable" name"mySubset" ...>
<key not-null="true" foreign-key="FK_MyObj" column="MyObject"/>
<map-key type="string" column="myAttribute"/>
<element type="string" column="myValue"/>
</map>
</class>
</hibernate-mapping>
也许这可以帮助别人...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.