wood burning stoves 2.0*
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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: MDBs and static HibernateUtil/Configuration
 
Similar Threads
DBCP could not obtain an idle db connection, pool exhausted
Data access ny multiple dao
Design benefits of creating Sessionfactory in an utility class
Class HibernateUtil cannot be resolved
could not read mapping from resource