org.hibernate.LazyInitializationException:
failed to lazily initialize a collection of role: com.yardbud.datamodel.Yard.images, could not initialize proxy - no Session
The exception above is well-known as using hibernate lazy fetching.
As the exception said, "no Session". The error is due to when fetching lazy attributes the session has been closed. typically, you load an entity using Hibernate session and work through it and then close it. The Hibernate doesn't support lazy initialization for a detached entity. Once the session is closed, then the entity cannot make any further call on the database.
So how to solve this issue?
Using static method Hibernate.initialize(entity.getXXX());
References:
The best way to handle the LazyInitializationException
Get org.hibernate.LazyInitializationException in spring boot integration test
Subscribe to:
Posts (Atom)
Can Jackson Deserialize Java Time ZonedDateTime
Yes, but must include JSR310. Thus ZonedDateTime can be deserialized directly from JSON response to POJO field. <dependency> <g...
-
Could not extract response: no suitable HttpMessageConverter found for response type [class dk.enettet.evu.core.model.Address] and content ...
-
First time met this hibernate exception. I think this issue should due to one to one relationship. One driver has one car; one car has on...
-
A large object refers to the entity property that is modified by @Lob. It may be persisted in several records. However, in database manage...