每次程序运行一段时间以后,就报此错
08-08-17 09:55:29 WARN JDBCExceptionReporter:71 - SQL Error: 17008, SQLState: null
08-08-17 09:55:29 ERROR JDBCExceptionReporter:72 - 关闭的连接
08-08-17 09:55:29 WARN JDBCExceptionReporter:71 - SQL Error: 17008, SQLState: null
08-08-17 09:55:29 ERROR JDBCExceptionReporter:72 - 关闭的连接
org.hibernate.exception.GenericJDBCException: could not execute query
Caused by: java.sql.SQLException: 关闭的连接
我的的struts2 +hibernate3
dao是
public Userinfo checkUserinfo(String name, String pwd) {
Session session = HibernateSessionFactory.getSession();
Transaction ta = session.beginTransaction();
Userinfo userinfo = (Userinfo) session.createCriteria(Userinfo.class)
.add(Expression.eq("userinfoName", name)).add(
Expression.eq("userinfoPassword", pwd)).uniqueResult();
ta.commit();
HibernateSessionFactory.closeSession();
return userinfo;
}
[b]问题补充:[/b]
package com.shop.hibernate.util;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.cfg.Configuration;
/**
pattern, see {@link http://hibernate.org/42.html }.
*/
public class HibernateSessionFactory {
/**
static {
try {
configuration.configure(configFile);
sessionFactory = configuration.buildSessionFactory();
} catch (Exception e) {
System.err
.println("%%%% Error Creating SessionFactory %%%%");
e.printStackTrace();
}
}
private HibernateSessionFactory() {
}
/**
SessionFactory
if needed. *@throws HibernateException
*/
public static Session getSession() throws HibernateException {
Session session = (Session) threadLocal.get();
if (session == null || !session.isOpen()) {
if (sessionFactory == null) {
rebuildSessionFactory();
}
session = (sessionFactory != null) ? sessionFactory.openSession()
: null;
threadLocal.set(session);
}
return session;
}
/**
/**
@throws HibernateException
*/
public static void closeSession() throws HibernateException {
Session session = (Session) threadLocal.get();
threadLocal.set(null);
if (session != null) {
session.close();
}
}
/**
/**
/**
}
这是自动生成的
Caused by: java.sql.SQLException: 关闭的连接
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:269)
at oracle.jdbc.driver.OracleConnection.privatePrepareStatement(OracleConnection.java:895)
at oracle.jdbc.driver.OracleConnection.prepareStatement(OracleConnection.java:802)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:396)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:334)
at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:88)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1162)
at org.hibernate.loader.Loader.doQuery(Loader.java:390)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
at org.hibernate.loader.Loader.doList(Loader.java:1593)
... 122 more
楼主如果确定是这块代码的问题, 能不能把HibernateSessionFactory的代码贴出来, 可能有两个原因:
1, 因为dao中你已经把session关闭, 如果Userinfo中使用了lazy加载, 那么就会拿不到session
2, HibernateSessionFactory.getSession()这个方法中拿到的session是同一个, 也说是单例的, 多线程共用一个session, 如果有一个线程把session关掉, 而其它的线程还没有执行完, 提交的时候也会发现已关闭, 应该是每次开一个新的session
你的service层中是怎么用DAO的?
感觉 你是在哪里没有打开session就开始使用查询。或者是你在DAO层中把session连接关闭了,然后又在service层中使用它。
没看出什么问题, 能不能把"Caused by: java.sql.SQLException: 关闭的连接 "这个异常的堆栈贴出来!也就是整个异常信息