Home  >  Article  >  Java  >  How to solve springboot jpa lazy loading problem

How to solve springboot jpa lazy loading problem

PHPz
PHPzforward
2023-05-12 13:58:111397browse

springboot jpa delayed loading problem

In springboot, the new spring.jpa.open-in-view=true method in the configuration file of application.properties fails

After testing, There are two solutions:

1. Add

spring.jpa.properties.hibernate.enable_lazy_load_no_trans=true;

to the configuration file of application.properties. 2. Add the @Transactional annotation to the test method.

About springboot lazy loading

Lazy loading or lazy loading means that when the spring container starts, it does not load all the beans into the spring container, but when needed time, this object is instantiated into the container.

Advantages:

Shorten startup time

Disadvantages:

If a configuration error occurs, it will not be found when the system starts, and strict testing is required, and It is necessary to ensure that the heap space of the JVM can satisfy all beans

Lazy loading is divided into global lazy loading and local lazy loading. Global lazy loading is achieved through configuration, and local lazy loading is achieved by adding @Lazy annotation to the class

The above is the detailed content of How to solve springboot jpa lazy loading problem. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete