One-to-many sleep mode display, strange example

We are trying to build a one-to-many relationship. Trying to understand how this works, we came across this example , which shows how to do it.

The example shows a reasonable ER diagram, but generally speaking, the one-to-many relationship does not need an auxiliary table. We could insert a column StudentIdinto a table Phoneand achieve a join by joining two tables with this identifier. In this example, in contrast, they need to join the three tables.

We are wondering if this behavior is justified by some good practice that simplifies management for Hibernate or is it just the mistake of the guy who wrote the article.

Any thoughts?

+3
source share
1 answer

I found the answer, and it seems like a kind of workaround ... http://en.wikibooks.org/wiki/Java_Persistence/OneToMany#Join_Table

As a general rule, it is best to define the ManyToOne backlink in Java, if you cannot or do not want to do this, then you can use an intermediate connection table to store the relationship. This is similar to ManyToMany relationships, but if you add a unique constraint to the target foreign key, you can ensure that it is OneToMany.

+2
source

Source: https://habr.com/ru/post/1785960/


All Articles