Spring jpa n+1 problem – what’s the suggestion?
Developers in their work encounter many problems, it may be inappropriate written code, or problems with the compilation of the program. Sometimes it is simply a human error, which made the mistake of writing a program, but sometimes the problem can be difficult to locate, as correctly written code may compile correctly. Probably spring jpa n + 1 problem is the most widely known and common problem for all tools for object-relational mapping that supports lazy loading. Side developer n + 1 may cause various problems with yield.
The problem of children parent-child relationship
This problem occurs when the code needs to load children parent-child relationship. Most ORM has a default lazy loading, so queries are issued for the parent record and then one question for each child record. As you would expect, perform queries (spring jpa n+1 problem) instead of a single query will cause flooding of database queries, and what we should avoid. Of course there is a solution for spring jpa n + 1 problem. The jpa there are many ways to solve it. In case you literally need the attributes of both sides of the relationship, it may be the best way. However, in most cases in the database code you are places where both are needed, as well as other when you need only the attributes of one. In this case the global downloading the type EAGER is like replacing one problem others. It can work for spring jpa n + 1 problem. The software must also be adequately tested after locating the error, it must go through the process of testing and verification.