hibernate项目运行一段时间后,JDBC报错

type Exception report

message JDBC commit failed

description The server encountered an internal error that prevented it from fulfilling this request.

exception

org.hibernate.TransactionException: JDBC commit failed
org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:161)
filter.TestFilter.doFilter(TestFilter.java:34)

root cause

com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Communications link failure during commit(). Transaction resolution unknown.
sun.reflect.GeneratedConstructorAccessor21.newInstance(Unknown Source)
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
java.lang.reflect.Constructor.newInstance(Constructor.java:526)
com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
com.mysql.jdbc.Util.getInstance(Util.java:408)
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:918)
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:897)
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:886)
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:860)
com.mysql.jdbc.ConnectionImpl.commit(ConnectionImpl.java:1559)
org.hibernate.transaction.JDBCTransaction.commitAndResetAutoCommit(JDBCTransaction.java:170)
org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:146)
filter.TestFilter.doFilter(TestFilter.java:34)

项目使用的是hibernate+struts2+Mysql;项目不是跑起来就报错,是运行一段时间后就报错。服务器重启就可以了,但一段时间后又报错。mysql驱动用3.0的时候也是这个情况,不过抱错是No operations allowed after connection closed;现在换成最新的5.o就报这个个错误。求高手解决。。。

事务我直接用了个过滤器
public class TestFilter implements Filter {

@Override
public void destroy() {
    // TODO Auto-generated method stub

}

@Override
public void doFilter(ServletRequest requ, ServletResponse respo,
        FilterChain chain) throws IOException, ServletException {
    HttpServletRequest request=(HttpServletRequest)requ;
    request.setCharacterEncoding("utf-8");
    Session session=HibernateSessionFactory.getSession();
    Transaction tr=session.beginTransaction();
    chain.doFilter(request, respo);

    tr.commit();------报错在这行,34行

    HibernateSessionFactory.closeSession();

}
@Override
public void init(FilterConfig arg0) throws ServletException {
    // TODO Auto-generated method stub
}

}

查看全部
wang08meng08
wang08meng08
2017/06/24 05:32
  • jdbc
  • hibernate
  • 点赞
  • 收藏
  • 回答
    私信

3个回复