• Post Reply Bookmark Topic Watch Topic
  • New Topic

MDBs and static HibernateUtil/Configuration  RSS feed

Jimmy Clark
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
  • 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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!