aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes MDBs and static HibernateUtil/Configuration Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "MDBs and static HibernateUtil/Configuration" Watch "MDBs and static HibernateUtil/Configuration" New topic
Author

MDBs and static HibernateUtil/Configuration

Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
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.
 
wood burning stoves
 
subject: MDBs and static HibernateUtil/Configuration