I have a problem with hibernation and lazy loading.
Background: I have a Spring MVC web application, I use Hibernate for my persistence level. I use OpenSessionInViewFilter to allow me to create lazy load objects at my presentation level. And I am extending the HibernateDaoSupport classes and using HibernateTemplate to save / load objects. Everything works very well. Still.
Problem: I have a task that can be launched using a web request. When a request is sent to the controller, the controller will create a new Runnable for this task and start the thread to complete the task. Thus, the original thread will be returned, and the Hibernate session that was placed in ThreadLocal (OpenSessionInViewFilter) is not available for the new thread for the task. Therefore, when a task does some database stuff, I get the notorious LazyInitializationException.
Can anyone suggest a better way to make a Hibernate session available for a task?
Thanks for reading.
source
share