D
D
dromanoff15012021-11-26 02:50:37
Hibernate
dromanoff1501, 2021-11-26 02:50:37

Why doesn't an infinite number of requests occur with bidirectional communication?

Good afternoon!

The following situation interests: for example, there are User and Role entities. Communication bidirectional many-to-many, fetchType Eager
Why doesn't the program go into an infinite number of requests, because in order to get the User, you must first get the Role, and to get the Role, you need to load the field with the User, etc.

Can you please explain how this happens "under the hood"?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2021-11-26
@dromanoff1501

Because Hibernate was not developed by fools, the library first builds an acyclic relationship graph, and then generates an SQL query based on it. Where the direction of the relationship is not obvious, the mappedBy attribute of the corresponding annotation is used.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question