我随机收到这个休眠错误,我无法重现它。
已有关联的托管连接
和堆栈跟踪如下...
INFO | jvm 1 | 2013/03/31 18:16:20 | org.hibernate.TransactionException: Transaction not successfully started
INFO | jvm 1 | 2013/03/31 18:16:20 | at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.commit(AbstractTransactionImpl.java:170)
INFO | jvm 1 | 2013/03/31 18:16:20 | at com.xxx.sss.helpers.HibernateUtil.getObjectsByCriteria(HibernateUtil.java:54)
我的选择器方法是这样的:
public static ArrayList<?> getObjectsByCriteria(String sqlQuery, List<Object> params, int firstResult, int maxSize)
{
ArrayList<Object> result = null;
try
{
SessionFactoryHelper.getSessionFactory().getCurrentSession().getTransaction().begin();
Query q = SessionFactoryHelper.getSessionFactory().getCurrentSession().createQuery(sqlQuery);
if(params != null)
{
for (int i = 0; i < params.size(); i++)
{
q.setParameter(i, params.get(i));
}
}
if(firstResult != -1 && maxSize != -1)
{
q.setFirstResult(firstResult);
q.setMaxResults(maxSize);
}
q.setReadOnly(true);
result = (ArrayList<Object>) q.list();
}
catch(HibernateException ex)
{
logger.log(Level.SEVERE, ex.getMessage());
logQueryAndParams(sqlQuery, params);
}
catch(Exception ex)
{
logger.log(Level.SEVERE, ex.getMessage());
logQueryAndParams(sqlQuery, params);
}
finally
{
if(!SessionFactoryHelper.getSessionFactory().getCurrentSession().getTransaction().wasCommitted())
SessionFactoryHelper.getSessionFactory().getCurrentSession().getTransaction().commit();
}
return result;
}
知道为什么我会得到这个吗?我用谷歌搜索了它,但很少有回应。我没有直接使用 Tomcat/Hibernate 的 Spring。
谢谢!