Hibernate:将两个类映射到一个公共的第三类
我正在寻找指向第三个类的两个类的多对一关系的正确映射。 下图显示了一个示例:
用文字表示; 一个人有 1..n 个地址 一家公司有 1..n 个地址,
我希望有一个包含所有地址的表。 目前,我只需要单向关系,但也很高兴看到它如何与双向关系一起工作。
我相信正确的数据库表示如下图
但我不知道如何翻译它使用 hibernate 注释将其放入 hibernat xml 文件或 java 类中。
这个问题5年前就在hibernate论坛讨论过: “https://forum.hibernate.org/viewtopic.php?t=961387” 但我认为他们没有找到令人满意的解决方案。
问候。
朱利安
I am searching for the correct mapping of a many-to-one relationship of two classes pointing on a third one.
An example is shown in the image below:
In words;
a Person has 1..n addresses
a Company has 1..n addresses
I'd like to have a single table for all addresses.
For the moment a uni-directional relation is all I need, but it would be also nice to see how this works with bi-directional relations.
I believe the correct database representation is like in the next image
But I don't know how to translate this into a hibernat xml file or a java class using hibernate annotations.
This problem has been discussed 5 years ago in the hibernate forum:
"https://forum.hibernate.org/viewtopic.php?t=961387"
but I think they found no satisfactory solution.
regards.
Julien
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一种非常正常的“带有连接表的单向一对多”关系,如 Hibernate 参考的第 8 章 和 注释参考的第 2 章。
That's a very normal "unidirectional one-to-many with join table" relationship as described in Chapter 8 of the Hibernate reference and Chapter 2 of the Annotations reference.