Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

After upgrading to spring-boot 3.2 I get LazyInitializationException #3724

Closed
Arsenii01 opened this issue Dec 20, 2024 · 1 comment
Closed
Labels
for: stackoverflow A question that's better suited to stackoverflow.com

Comments

@Arsenii01
Copy link

Arsenii01 commented Dec 20, 2024

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)

@Arsenii01 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
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Dec 20, 2024
@schauder schauder added for: stackoverflow A question that's better suited to stackoverflow.com and removed status: waiting-for-triage An issue we've not yet triaged labels Dec 20, 2024
@schauder
Copy link
Contributor

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.

@schauder schauder closed this as not planned Won't fix, can't repro, duplicate, stale Dec 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: stackoverflow A question that's better suited to stackoverflow.com
Projects
None yet
Development

No branches or pull requests

3 participants