gpt4 book ai didi

java - Hibernate session 无法打开事务

转载 作者:行者123 更新时间:2023-11-29 01:57:39 24 4
gpt4 key购买 nike

有人能告诉我以下异常吗?我每天尝试登录几次后都会收到此异常。但经过几次尝试后它消失了,第二天又出现了。

以下是异常(exception)情况:

异常

> org.springframework.web.util.NestedServletException: Request
> processing failed; nested exception is
> org.springframework.transaction.CannotCreateTransactionException:
> Could not open Hibernate Session for transaction; nested exception is
> org.hibernate.TransactionException: JDBC begin failed:
> org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:656)
> org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)
> javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
> javax.servlet.http.HttpServlet.service(HttpServlet.java:717) root
> cause
>
> org.springframework.transaction.CannotCreateTransactionException:
> Could not open Hibernate Session for transaction; nested exception is
> org.hibernate.TransactionException: JDBC begin failed:
> org.springframework.orm.hibernate3.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:596)
> org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:371)
> org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:335)
> org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:105)
> org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
> org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
> $Proxy48.loginUser(Unknown Source)
> com.sapat.competition_tracker.controller.AdminController.userLogin(AdminController.java:59) sun.reflect.GeneratedMethodAccessor510.invoke(Unknown Source)
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> java.lang.reflect.Method.invoke(Method.java:616)
> org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)
> org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:427)
> org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:415)
> org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:788)
> org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:717)
> org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
> org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)
> javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
> javax.servlet.http.HttpServlet.service(HttpServlet.java:717) root
> cause
>
> org.hibernate.TransactionException: JDBC begin failed:
> org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:96)
> org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1354)
> org.springframework.orm.hibernate3.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:555)
> org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:371)
> org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:335)
> org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:105)
> org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
> org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
> $Proxy48.loginUser(Unknown Source)
> com.sapat.competition_tracker.controller.AdminController.userLogin(AdminController.java:59) sun.reflect.GeneratedMethodAccessor510.invoke(Unknown Source)
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> java.lang.reflect.Method.invoke(Method.java:616)
> org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)
> org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:427)
> org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:415)
> org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:788)
> org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:717)
> org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
> org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)
> javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
> javax.servlet.http.HttpServlet.service(HttpServlet.java:717) root
> cause
>
> com.mysql.jdbc.CommunicationsException: Communications link failure
> due to underlying exception:
>
> ** BEGIN NESTED EXCEPTION **
>
> java.io.EOFException
>
> STACKTRACE:
>
> java.io.EOFException at
> com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:1963) at
> com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2375) at
> com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2874) at
> com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1623) at
> com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1715) at
> com.mysql.jdbc.Connection.execSQL(Connection.java:3243) at
> com.mysql.jdbc.Connection.setAutoCommit(Connection.java:5371) at
> org.apache.commons.dbcp.DelegatingConnection.setAutoCommit(DelegatingConnection.java:331)
> at
> org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.setAutoCommit(PoolingDataSource.java:317)
> at
> org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:91)
> at
> org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1354)
> at
> org.springframework.orm.hibernate3.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:555)
> at
> org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:371)
> at
> org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:335)
> at
> org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:105)
> at
> org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
> at
> org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
> at $Proxy48.loginUser(Unknown Source) at
> com.sapat.competition_tracker.controller.AdminController.userLogin(AdminController.java:59) at sun.reflect.GeneratedMethodAccessor510.invoke(Unknown Source) at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.lang.reflect.Method.invoke(Method.java:616) at
> org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)
> at
> org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:427)
> at
> org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:415)
> at
> org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:788)
> at
> org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:717)
> at
> org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
> at
> org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:637) 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
> 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:127)
> 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:298)
> at
> org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
> at
> org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
> at
> org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
> at java.lang.Thread.run(Thread.java:679)
>
>
> ** END NESTED EXCEPTION **
>
>
>
> Last packet sent to the server was 1 ms ago.
> com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2586)
> com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2874)
> com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1623)
> com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1715)
> com.mysql.jdbc.Connection.execSQL(Connection.java:3243)
> com.mysql.jdbc.Connection.setAutoCommit(Connection.java:5371)
> org.apache.commons.dbcp.DelegatingConnection.setAutoCommit(DelegatingConnection.java:331)
> org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.setAutoCommit(PoolingDataSource.java:317)
> org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:91)
> org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1354)
> org.springframework.orm.hibernate3.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:555)
> org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:371)
> org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:335)
> org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:105)
> org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
> org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
> $Proxy48.loginUser(Unknown Source)
> com.sapat.competition_tracker.controller.AdminController.userLogin(AdminController.java:59) sun.reflect.GeneratedMethodAccessor510.invoke(Unknown Source)
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> java.lang.reflect.Method.invoke(Method.java:616)
> org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)
> org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:427)
> org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:415)
> org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:788)
> org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:717)
> org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
> org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)
> javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
> javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

最佳答案

这是一个迟到的答案,但我遇到过同样的问题。是c3po配置不当造成的。

请使用以下c3po配置:

<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="${jdbc.driverClassName}" />
<property name="jdbcUrl" value="${jdbc.url}" />
<property name="user" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />

<property name="checkoutTimeout" value="30000" />
<property name="idleConnectionTestPeriod" value="30"/>
<property name="initialPoolSize" value="10" />
<property name="maxIdleTime" value="30" />
<property name="maxPoolSize" value="100" />
<property name="minPoolSize" value="10" />
<property name="maxStatements" value="10" />

</bean

关于java - Hibernate session 无法打开事务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24053684/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com