Hibernate 映射一对多,奇怪的例子
我们正在尝试建立一对多的关系。为了理解它是如何工作的,我们偶然发现了 这个例子,它展示了如何做到这一点。
该示例显示了一个合理的 ER 图,但一般来说,在一对多关系中不需要辅助表。我们可以将 StudentId
列插入到 Phone
表中,并通过此标识符连接两个表来实现链接。相比之下,在该示例中,他们需要连接三个表。
我们想知道这种行为是否是由一些使 Hibernate 易于管理的良好实践证明是合理的,或者这是否只是撰写本文的人的错误。
有什么想法吗?
We are trying to build a One-to-many relation. Trying to understand how this works, we stumbled across this example, which shows how to do it.
The example shows a reasonable ER diagram, but generally speaking in a One-to-many relation one doesn't need an auxiliary table. We could insert a StudentId
column into the Phone
table and achieve the linking by joining the two tables through this identifier. In the example, by contrast, they need to join three tables instead.
We are wondering if such a behaviour is justified by some good practice which makes the management easy for Hibernate or if it's just an error of the guy who wrote the article.
Any thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了答案,看来这正是一种解决方法......
http://en.wikibooks.org/wiki/Java_Persistence/OneToMany#Join_Table
I've found an answer, and it seems it's exactly a sort of workaround...
http://en.wikibooks.org/wiki/Java_Persistence/OneToMany#Join_Table