0

This is a well known issue of Spring MVC with Hibernate/JPA, "failed to lazily initialize a collection of role no session or session was closed". See Hibernate: failed to lazily initialize a collection of role, no session or session was closed

Many posts suggest using EAGER to replace LAZY, which can work but has performance lost. Is there a good solution for this issue?

Thanks.

Community
  • 1
  • 1
frogcdcn
  • 391
  • 1
  • 4
  • 14

1 Answers1

1

This generally happens when you have your transaction management inside your DAO. The best practice is to write a service on top of the DAO and do all the gets/populations in your services. And apply transactions in services.

This way you shield your Domain models being accessed out of a database session and your services decide wether to load the children or not based on what it is supposed to do.

Johnson Abraham
  • 771
  • 4
  • 12