欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Could not toggle autocommit Session is closed

程序员文章站 2022-05-25 10:30:26
...

错误提示:

Hibernate: select count(*) from product
2013-03-14 15:40:53 ERROR [JDBCTransaction.java:232] org.hibernate.transaction.JDBCTransaction.toggleAutoCommit() - Could not toggle autocommit
org.hibernate.SessionException: Session is closed
	at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:139)

 

原因:

spring3.0     session不用关,我关了。。。

/**
	 * 查询总数量
	 * @param hql
	 * @return
	 */
	public int findResultByHql(String hql){
		Session session=this.getSession();
		try {
			Query query=session.createQuery(hql);
			return Integer.parseInt(query.uniqueResult().toString()) ;
		}finally{
			session.close();
	    }
		
	}

 

相关标签: Spring3 Hibernate