Home ManyToMany: what is the correct or best way to go in JPA?
Reply: 1

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

NikolayZ Published in 2018-01-10 22:07:15Z

I’m new to JPA and studying. 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.

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).

Or should I also make a "join" 3rd entity AuthorsBooks with JPA? 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!

NikolayZ Reply to 2018-01-14 13:35:30Z

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)

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.305526 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO