June 2018
Intermediate to advanced
408 pages
11h 23m
English
We saw in the preceding section that in order to defer fetching until the associated entity is needed, we set the fetch type of the associated entities as LAZY. When we try to access these associated entities in our presentation layer (if they are not initialized in our business (service) layer), an exception is thrown by Hibernate, called LazyInitializationException. When the service layer method completes its execution, Hibernate commits the transaction and closes the session. So, by the time the view is rendered, the active session is not available to fetch the associated entities.
To avoid LazyInitializationException, one of the solutions is an open session in view. This means that we keep the Hibernate ...
Read now
Unlock full access