I am working on a J2EE server application that is deployed to Tomcat. I am using Spring as an MVC framework and Hibernate as an ORM provider. My object model has many Lazy relationships (dependent objects are selected on request). A high-level design is similar to service-level methods that invoke several DAO methods to perform database operations. The service method is called either from the Flex user interface or as a scheduled task. When it is called from the Flex interface, the service method works fine, that is, it retrieves some objects using DAO methods and even Lazy boot. This is possible using the OpenSessionInViewFilter configured using the UI servlet.
But when the same service method is called as a scheduled task, it throws a LazyInitializationException. I cannot configure OpenSessionInViewFilter because the servlet or user interface is not associated with it.
I tried to set up a transaction around the scheduled task method so that the service method started the transaction and all DAO methods participated in the same transaction, hoping that the transaction would remain active and the hibernation session would be available. But that does not work.
Please suggest anyone ever get such a configuration. If necessary, I can publish the Hibernate configuration and log messages.
Many thanks for the help!
Shreerang
source share