ssh 框架 反复运行这个DAO后 显示 Cannot get a connection, pool error Timeout waiting for idle object
- Java code
public class DeviceAlarmDAOImpl extends HibernateDaoSupport implements DeviceAlarmDAO { private HibernateTemplate ht; public void init() { ht = getHibernateTemplate(); }。。。。。。。Session session = this.getSession();String hql = "select count(alarmID) from DeviceAlarmInfo";int total = 0; try { Query query = session.createQuery(hql); total = ((Number) query.uniqueResult()).intValue(); return Integer.valueOf(total); } catch (Exception e) { e.printStackTrace(); return 0; } finally { session.close(); }
maxActive maxIdle maxWait 设置没问题 因为运行其他DAO没错误
------解决方案--------------------------------------------------------
用HQL试试
------解决方案--------------------------------------------------------
查查是不是有地方,没有进行 session.close();
------解决方案--------------------------------------------------------
数据库服务没启吧?或者检查你的sessionFactory的配置。
------解决方案--------------------------------------------------------
session.close()是不对的,应该去掉。比如dao.update();dao.save();是紧邻的两句。那你是不是close了两次呢?close操作应该放在service层。