Hibernate需要每天重启一道的奇怪问题,请大虾指点!
我有一个Web程序,每次运行之后都很正常,但是一到第二天早上再来登陆的时候,就报错,说连接已经关闭。需要重启,但是只能管一天!
No operations allowed after connection closed. Connection was closed due to the following exception: ** BEGIN NESTED EXCEPTION ** java.sql.SQLException MESSAGE: Communication link failure: java.net.SocketException, underlying cause: Software caused connection abort: recv failed ** BEGIN NESTED EXCEPTION ** java.net.SocketException MESSAGE: Software caused connection abort: recv failed STACKTRACE: java.net.SocketException: Software caused connection abort: recv failed at java.net.SocketInputStream.socketRead0(Native Method) at…………
………………
引起错误的代码如下:
public UserInfo authenticate() throws Exception {
try {
Session session = HibernateUtil.currentSession();
session.beginTransaction();
Query q = session.createQuery("select u from u in class UserInfo where u.email=:email and u.password=:password");
q.setParameter("email", getEmail());
q.setParameter("password", getPassword());
List result = q.list();
if (!result.isEmpty()) {
return (UserInfo)result.iterator().next();
}
else {
ValidationDelegate delegate = (ValidationDelegate) getBeans().getBean("delegate");
delegate.setFormComponent(null);
delegate.record("Login failed, wrong username or password", null);
}
session.beginTransaction().commit();
} catch (HibernateException e) {
HibernateUtil.currentSession().beginTransaction().rollback();
e.printStackTrace();
} finally {
if (HibernateUtil.currentSession() != null)
try {
HibernateUtil.currentSession().flush();
HibernateUtil.closeSession();
} catch (Exception e) {
e.printStackTrace();
}
}
return null;
}