Studying JPA . And studying связи . I can not understand the difference between these 2 annotations. This is how OneToOne looks OneToOne - in one table a foreign key is created on another table.

enter image description here

This is how OneToMany looks OneToMany - one table is created that links the other two tables. But you can also configure it using @JoinColumn that it would not create a table, but a внешний ключ . What are the differences then? OneToMany be implemented like this? OneToMany is a список with entities. Those. data structure with data structures inside. Shouldn't it be implemented as a bd with bd? enter image description here

And one more question: Suppose I have E1 и E2 . Why do you need bidirectional communication? So that I can change E1 interacting with E2 and change E2 interacting with E1 ? Can anyone answer? heya

  • one
    You just need to read about the device relational database - Serhii Dikobrazko

1 answer 1

Alexey, what would you like to wish for is to focus on understanding the concept of persistence and the fact that JPA provides this persistence. As for the annotations mentioned, they are guidelines for JPA how to ensure the persistence of the properties marked by them. For example, when you request a property value, JPA itself (without your participation) will determine, based on the specified annotation, what kind of query is needed to get data (maybe a list of data) from the database. If you are going to manually maintain persistence in this part of the task, then you are not required to use these annotations.

  • Persistence sounds better, though longer - Oleksiy Morenets
  • It would be even better to translate it into Russian, but I do not know how. - Orthodox
  • @Orthodox just now saw your answer when I figured it out, but thanks anyway. Persistence is a kind of constancy - Alex
  • Alexey, persistence is when an application has Load and Save items in the menu - Orthodox 1:56 pm