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...
-
The strictfp keyword is used to force the precision of floating point calculations (float or double) in Java conform to IEEE’s 754 standard...
-
As the name implies, an anonymous inner class isn’t defined using an explicit name. An anonymous inner class is created when you combine ins...
-
In construction. Spring test annotations: @SpringBooTest @DataJpaTest @TestPropertySource @ActiveProfiles @Sql @SpringBootTest It is used f...