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

org.hibernate.TransactionException: JDBC begin failed解决方案

程序员文章站 2022-07-11 07:51:11
...

org.hibernate.TransactionException: JDBC begin failed:
    at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:68)
    at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:
1326)
    at com.stable.application.common.hibernate.HibernateSessionFactory.beginTransaction(HibernateSessionFactory.java:
136)
    at com.stable.application.common.struts.AduActionServlet.process(AduActionServlet.java:
78)
    at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:
414)
    at com.stable.application.common.struts.AduActionServlet.doGet(AduActionServlet.java:
104)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:
617)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:
717)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:
290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:
206)
    at com.stable.application.common.http.filter.UserSessionFilter.doFilter(UserSessionFilter.java:
57)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:
235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:
206)
    at com.stable.application.common.http.filter.RequestEncodeFilter.doFilter(RequestEncodeFilter.java:
51)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:
235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:
206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:
233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:
191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:
128)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:
102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:
109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:
293)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:
849)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:
583)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:
454)
    at java.lang.Thread.run(Thread.java:
619)
Caused by: java.sql.SQLException: Couldn
't perform the operation getAutoCommit: You can't perform any operations on this connection. It has been automatically closed by Proxool for some reason (see logs).
    at org.logicalcobwebs.proxool.WrappedConnection.invoke(WrappedConnection.java:
207)
    at org.logicalcobwebs.proxool.WrappedConnection.intercept(WrappedConnection.java:
87)
    at $java.sql.Wrapper$$EnhancerByProxool$$1cc186b6.getAutoCommit(
<generated>)
    at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:
57)
    ...
25 more

开发环境:(tomcat,ssh,DBCP连接池)

出现此异常的情况介绍:访问项目搁置一段时间再访问的时候,就出现了如上的异常;

解决方案:

    在spring配置文件中配置数据源的时候,添加如下几项属性配置:

  <!-- 下面三项是确保获得的连接是有效的 -->

  <property name="testOnBorrow" value="true"></property>
  <property name="testOnReturn" value="true"></property>

  <property name="testWhileIdle" value="true"></property>

   <property name="validationQuery" value="SELECT 1"></property>

   <property name="timeBetweenEvictionRunsMillis" value="检查无效连接的时间间隔"></property>
   <property name="minEvictableIdleTimeMillis" value="连接闲置的时间"></property>

 

参考网址:(http://s.yanghao.org/program/viewdetail.php?i=101009