You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello. My project was using spring boot 3.1.12, and I upgraded version to 3.2.0, but I started getting org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: could not initialize proxy - no Session when trying to access child entities of my parent entity.
spring-boot-starter-jpa:3.2.0 uses Hibernate 6.3, in migration guide there is a paragraph 'Batch Fetching and LockMode', maybe this new behavor is the cause of my problem. How can I fix it, if I use Spring Data JPA? My method is annotated with @Transactional and it worked fine before
@EntityGraph is not an option because it increases endpoint response time too much, the same goes for fetch join query (Hibernate will make 2 fetch joins in query for each parent entity, of which there may be many)
The text was updated successfully, but these errors were encountered:
Arsenii01
changed the title
After upgrading to spring-boot 3.2 I get LazyInitializedError
After upgrading to spring-boot 3.2 I get LazyInitializationException
Dec 20, 2024
This issue tracker is for bug reports and feature/improvement requests for Spring Data JPA
This question is more of a usage questions and it is completely based on Hibernate/JPA, since Hibernate implements all the lazy loading logic.
Those should be asked at Stackoverflow and be tagged with hibernate.
By using Stackoverflow, the community can assist and the questions and their answers can more easily be found using the search engine of your choice. And by tagging it with Hibernate you reach the appropriate audience that might be able to help with this.
That said in general you need to keep your transaction open until all your lazy instances that you actaually need are properly initialised. Either by extending the scope of the transaction (Open Session in View is an approach to consider), or by explicitly initialising proxies within the transaction.
Hello. My project was using spring boot 3.1.12, and I upgraded version to 3.2.0, but I started getting
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: could not initialize proxy - no Session
when trying to access child entities of my parent entity.spring-boot-starter-jpa:3.2.0 uses Hibernate 6.3, in migration guide there is a paragraph 'Batch Fetching and LockMode', maybe this new behavor is the cause of my problem. How can I fix it, if I use Spring Data JPA? My method is annotated with
@Transactional
and it worked fine before@EntityGraph
is not an option because it increases endpoint response time too much, the same goes forfetch join
query (Hibernate will make 2 fetch joins in query for each parent entity, of which there may be many)The text was updated successfully, but these errors were encountered: