I have created a simple Spring boot project with Spring data.
I have a TagGroup Entity which has one to many relation with Tags.
@Entity
@Table(name =
This is because of property spring.jpa.open-in-view=true
.
As per the spring-boot-configuration Spring boot applications use spring.jpa.open-in-view=true
.
With this property it
Register OpenEntityManagerInViewInterceptor. Binds a JPA EntityManager to the thread for the entire processing of the request.
So in your case, subsequently when you call the getTagList()
i.e., retrieve the tagList
, it subsequently fires another query to fetch the tagList
as the the EntityManager
is still open.
As you might know, LazyInitializationException
is never thrown if the entityManager
that has loaded the parent is still open.
To override this, you can add spring.jpa.open-in-view=false
in your application.properties/application.yml
and then you should see LazyInitializationException
.