I'm writing a web app that is basically a Spring-configured Quartz scheduler. The various Jobs I need to run depend on a seperate Dao package, containing Dao classes that extend Spring's HibernateDaoSupport. These Dao's are all configured in the same ContextConfig as my Quartz jobs,etc.
Everything runs smoothly, up until I try to use the Dao methods (findAll, save, etc). At which point I get various Hibernate session-rlated errors, such as "org.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions".
I have a separate Spring MVC web app that uses the Same DAO classes with an OpenSessionInViewInterceptor, with absolutely no problems. How can I replicate this behavior in a Quartz job that, essentially, has no view?
Here is the code (abridged) of the job's executeInternal method:
So I guess, right at the start of the executeInternal method, I need to open a Hibernate session, then attach all my various Dao calls to that session somehow, and close it when I'm done. How can I do this?
Joined: Mar 29, 2006
heheh. As usual, when it comes to hibernate, the community is silent (either because everyone knows the answer, but isn't telling, or because there is no answer).
Well, getting desperate now, Can anyone give me a compelling reason why I wouldn't open a Hibernate session, say, when Tomcat starts, then close it on shutdown? From what I understand, I can use multiple Transactions within a session, so what's to prevent me from using a single session over the (probably extremely LONG) lifetime of the application?
...Something tells me this is a bad idea, and yet I can't think of why...