permaculture playing cards*
The moose likes Object Relational Mapping and the fly likes Usual problems managing Hibernate sessions... PLEASE HELP? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Usual problems managing Hibernate sessions... PLEASE HELP?" Watch "Usual problems managing Hibernate sessions... PLEASE HELP?" New topic
Author

Usual problems managing Hibernate sessions... PLEASE HELP?

Philippe Desrosiers
Ranch Hand

Joined: Mar 29, 2006
Posts: 138
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?
Philippe Desrosiers
Ranch Hand

Joined: Mar 29, 2006
Posts: 138
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...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Usual problems managing Hibernate sessions... PLEASE HELP?