Could not toggle autocommit Session is closed

错误提示:

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();
	    }
		
	}

 

你可能感兴趣的:(Hibernate,Spring3)