• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

MDBs and static HibernateUtil/Configuration

 
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the onMessage() method of a Message-Driven Bean there is code that uses a HibernateUtil class to get a reference to a SessionFactory. The code for creating the SessionFacotry is implemented in a static initialization block in the HibernateUtil class.



This static initialization block executes when the class is loaded in the application server's JVM. And the class is loaded when the code is deployed. Is this correct?

The problem we are facing is that when a series of messages are put on the queue, we are gettting a stale connection to the database and one record fails to be processed. In other words, a series of MDBs are called by the container and they all use this HibernateUtil class to write to the database. It is usually the first record processed, but sometimes the second or third that fails.

How to make sure that this HibernateUtil will always have fresh connections or a SessionFactory with a live database connection is the issue, I think?

Any ideas.
 
reply
    Bookmark Topic Watch Topic
  • New Topic