我需要从数据库中获取一些数据。为此,我编写了类似的代码
try{
return (EmployeeImpl) em.createQuery(
"select e from EmployeeImpl e " +
"where e.empName = :employeeName " +
" and (e.eDate is null or e.eDate <= :todaysDate )")
.setParameter("employeeName", employeeName)
.setParameter("todaysDate", todaysDate)
.getSingleResult();
}catch(NoResultException exception){
throw new NoResultException("Record not found");
}
我应该返回一份有效记录。但给出了例外
org.hibernate.util.JDBCExceptionReporter] 事务未激活:tx=TransactionImple < ac, BasicAction: 0:ffff0a5308fa:126a:4fb36c77:559 状态:ActionStatus.ABORT_ONLY >; - 嵌套 throwable:(javax.resource.ResourceException:事务未激活:tx=TransactionImple < ac,BasicAction:0:ffff0a5308fa:126a:4fb36c77:559 状态:ActionStatus.ABORT_ONLY >)
org.hibernate.exception.GenericJDBCException: Cannot open connection
javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Cannot open connection
我的应用程序可以连接到数据库,因为我可以在其他地方执行 CRUD 操作。
此异常的可能原因是什么。