Hibernate 中的自引用一对一映射
我有一个 A 类,它有一个属性类型,指示它是收据还是交货。收据可以映射到单个交付,反之亦然。现在考虑收货交易和交付交易是同级交易。
因此,A 类有一个类型为 A 的同级。“A”及其同级具有上面建立的一对一关系。
Class A {
private A sibling;
}
<hibernate-mapping>
<class name="A" table="A">
<id name="Id" type="java.lang.Integer" column="id">
<generator class="native"></generator>
</id>
<one-to-one name="sibling" class="A" lazy="proxy" />
</class>
</hibernate-mapping>
我无法找出创建自引用一对一映射的方法。
I have a class A which has a property type indicating whether it is a receipt or a delivery. A receipt can be mapped to a single delivery and vice-versa. Now consider that the receipt transaction and the delivery transaction are siblings.
So class A has a sibling of type A. "A" and its sibling have a one-to-one relationship as established above.
Class A {
private A sibling;
}
<hibernate-mapping>
<class name="A" table="A">
<id name="Id" type="java.lang.Integer" column="id">
<generator class="native"></generator>
</id>
<one-to-one name="sibling" class="A" lazy="proxy" />
</class>
</hibernate-mapping>
I am unable to figure out a way to create a self-referencing one-to-one mapping.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用
多对一
单向关联。请参阅单向关联 在 hibernate 参考文档中。您可以阅读这些答案以获取有关
Use the
many-to-one
unidirectional association. See Unidirectional associations in the hibernate reference documentation.You can read those answers for more information on