Hi,
We are using Hibernate 2.1.7 with Ingress Database and EDBC (edbc.jar) as a jdbc driver for my web application. Things are working fine for single user. If more then one user try to access (getting ) data from same table then I am getting Deadlock exception.
Can anyone please help us.
Hibernate Utility
public class HibernateUtility
{
private static final SessionFactory sessionFactory;
private static final ThreadLocal session = new ThreadLocal();
private static final ThreadLocal transaction = new ThreadLocal();
private static final String HIBERNATE_FACTORY =
"java:/hibernate/HibernateFactory";
static
{
try
{
// Create the SessionFactory
Context ctx = new InitialContext();
sessionFactory = (SessionFactory) ctx
.lookup(HIBERNATE_FACTORY);
}
catch (Throwable ex)
{
throw new ExceptionInInitializerError(ex);
}
}
private static Session currentSession() throws HibernateException
{
synchronized (session)
{
Session s = (Session) session.get();
// Open a new Session, if this Thread has none yet
if (s == null)
{
s = sessionFactory.openSession();
session.set(s);
}
return s;
}
}
private static void closeSession() throws HibernateException
{
synchronized (session)
{
Session s = (Session) session.get();
session.set(null);
if (s != null)
{
s.close();
}
s = null;
}
}
private static void beginTransaction() throws HibernateException
{
synchronized (transaction)
{
Transaction tx = (Transaction)transaction.get();
if(tx == null)
{
tx = currentSession().beginTransaction();
transaction.set(tx);
}
}
}
public static void commitTransaction() throws HibernateException
{
synchronized (transaction)
{
Transaction tx = (Transaction)transaction.get();
try
{
if(tx != null &&
!tx.wasCommitted() &&
!tx.wasRolledBack())
{
tx.commit();
}
tx = null;
transaction.set(null);
}
catch(HibernateException ex)
{
rollbackTransaction();
throw ex;
}
}
}
private static void rollbackTransaction() throws HibernateException
{
synchronized (transaction)
{
Transaction tx = (Transaction)transaction.get();
try
{
transaction.set(null);
if(tx != null &&
!tx.wasCommitted() &&
!tx.wasRolledBack())
{
tx.rollback();
}
}
finally
{
closeSession();
}
}
}
}
Exception
Caused by: ca.edbc.util.EdbcEx: Deadlock detected, your single or multi-query transaction has been aborted.
at ca.edbc.jdbc.EdbcObj.readResults(Unknown Source)
at ca.edbc.jdbc.EdbcObj.readResults(Unknown Source)
at ca.edbc.jdbc.EdbcPrep.exec(Unknown Source)
at ca.edbc.jdbc.EdbcPrep.executeQuery(Unknown Source)
at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.executeQuery(WrappedPreparedStatement.java:314)
at net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:87)
at net.sf.hibernate.loader.Loader.getResultSet(Loader.java:800)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:189)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:915)
at net.sf.hibernate.loader.Loader.loadCollection(Loader.java:890)
at net.sf.hibernate.loader.OneToManyLoader.initialize(OneToManyLoader.java:93)
at net.sf.hibernate.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:284)
... 76 more
|