[英]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.