Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger

Usual problems managing Hibernate sessions... PLEASE HELP?

Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
Normally trees don't drive trucks. Does this tiny ad have a license?
Devious Experiments for a Truly Passive Greenhouse!
    Bookmark Topic Watch Topic
  • New Topic