简体   繁体   中英

How to change JPA default fetching to LAZY

I want to change by default loading of all beans to lazy we can change it manually by changing every join fetch type to lazy but is there any way that I can change the default value of JPA so I don't have to change it manually

I am using spring boot project is there any way I can change it from application.properties file?

Thanks

Even if there was a global configuration like this (and there is none) your JOIN FETCH on the query level would override that setting anyway. The way the queries are structured always takes higher precedence than that of the global set-up.

Regarding the situation where you only use JOIN without the FETCH , the persistence provider may still decide to use EAGER fetching anyway:

The LAZY strategy is a hint to the persistence provider runtime that data should be fetched lazily when it is first accessed. The implementation is permitted to eagerly fetch data for which the LAZY strategy hint has been specified.

So there is no way to 100% ensure LAZY loading throughout the project.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM