简体   繁体   English

ManyToMany:采用JPA的正确或最佳方法是什么?

[英]ManyToMany: what is the correct or best way to go in JPA?

I'm new to JPA and studying. 我是JPA和学习的新手。 When I have Many-to-Many relationship b/w tables in SQL for example Author and Book: I used a join table AuthorBook with composite primary key. 当我在SQL中具有多对多关系黑白表(例如Author和Book)时:我使用了带有复合主键的联接表AuthorBook。

How should do it in JPA: Should I make only two entities Author and Book and create relationship ManyToMany with mappingBy one of them (in Author for example) and make another own owner of relationship: in Books (with using joinColumns). 在JPA中应该如何做:我应该只让两个实体Author和Book并使用mapping创建关系ManyToMany通过其中之一(例如在Author中),并让关系的另一个拥有者:在Books中(使用joinColumns)。

Or should I also make a "join" 3rd entity AuthorsBooks with JPA? 还是我也应该与JPA进行“加入”第三实体AuthorsBooks? What way is correct? 哪种方法是正确的? Are there actually different ways or an only way a preferable way? 实际上有不同的方法还是唯一的更好的方法?

Besides my specific question, I wonder if somebody know a good example/tutorial on this question? 除了我的特定问题外,我想知道是否有人对这个问题有很好的例子/教程? (I couldn't find a good one) Thanks! (我找不到一个好的)谢谢!

I found different sources with solution. 我找到了解决方案的不同来源。 the best in my opinion is like here: think is here https://en.wikibooks.org/wiki/Java_Persistence/ManyToMany They say it's a standard way to make two entities with manyToMany association, however if the join table supposed to have additional columns is a best way to make three entities including an entity for join table (examples are given in the link for both situations) 我认为最好的就是这里:认为这里https://en.wikibooks.org/wiki/Java_Persistence/ManyToMany他们说这是使两个具有manyToMany关联的实体的标准方法,但是如果联接表应该具有附加的列是制作三个实体(包括用于联接表的实体)的最佳方法(两种情况下的链接中均提供了示例)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 map @ManyToMany 与 JPA 和 Hibernate 关系的最有效方法是什么? - What is the most efficient way to map @ManyToMany relationship with JPA and Hibernate? 将Vaadin CheckBox保存到JPA的正确方法是什么? - What is the correct way to save a Vaadin CheckBox to JPA? 在 JPA 中更新实体的最佳方法是什么 - What is the best way to update the entity in JPA JPA初始化数据的最佳方法是什么? - What is the best way to initialize data by JPA? JPA @ManyToMany关联似乎仅以一种方式工作 - JPA @ManyToMany associations seem to only be working 1 way 在 EJB 中捕获 JPA 异常的正确方法是什么 - What is the correct way to catch a JPA exception within an EJB 在JPA中实现互斥关系的最佳方法是什么? - What is the best way to implement mutually exclusive relationship in JPA? 在spring boot jpa中存储日期的最佳方法是什么? - What's the best way to store date in spring boot jpa? 使用 Java Hibernate 和 Z9CE3D1BD8890F916A0C44809 获得 model 友谊的最佳方式是什么 - What's the best way to model Friendship using Java Hibernate and JPA 在JPA中选择具有子实体的许多实体的最佳优化方法是什么? - What is the best optimized way to select many entities with subentities in JPA?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM