Answer the question
In order to leave comments, you need to log in
Hibernate ( FetchType.LAZY and session close)?
Hello everyone, I've run into this problem.
The project uses Hibernate and HikariCP(connection pool), PostgresSQL database.
In general, all objects use lazy loading of connected data, but here there is a problem with closing the session.
That is, when receiving data, I cannot write session.close(); Since part of the connected data will be pulled up later. And I get an exception:
"org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.slandshow.models.Train.seats, could not initialize proxy - no Session
" but this approach does not suit me for performance reasons.
Since sessions are not closed, the only thing left is to increase the connection pool by several thousand. But this is also somehow not ice.
Can anyone suggest how to solve this problem?
Answer the question
In order to leave comments, you need to log in
You can use a DTO and several methods to fill it: one for an object without nested data, others for an object with nested data (or part of it).
Anyway, you will serialize the object - at this stage, its content should already be clear.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question