首次登录时无法打开Hibernate Session进行交易 [英] Could not open Hibernate Session for transaction on First Login

查看:457
本文介绍了首次登录时无法打开Hibernate Session进行交易的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个完整运行的Spring Mvc应用程序与Spring Security一起运行但是每当服务器暂时没有激活并且有人试图登录时我都会收到以下错误:

I have a full operating Spring Mvc Application running with Spring Security but i get the following error whenever the server hasn't been active in a while and someone tries to login:

HTTP状态500 - 请求处理失败;嵌套异常是org.springframework.transaction.CannotCreateTransactionException:无法打开Hibernate Session进行事务处理;嵌套异常是org.hibernate.TransactionException:JDBC开始事务失败

HTTP Status 500 - 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 transaction failed

有时(大约5秒后)它开始正常工作。

Sometimes after (approximately 5 seconds later) it starts to work normally.

我搜索并找到了这个链接:
http://forum.spring.io/forum/spring-projects/data/13298-could-not-open-hibernate-session-for -transaction-jdbc-begin-failed
但我不知道如何在连接池配置中配置连接测试。

I searched and found this link: http://forum.spring.io/forum/spring-projects/data/13298-could-not-open-hibernate-session-for-transaction-jdbc-begin-failed but i don't know how to "configure connection testing in the connection pool configuration".

有什么建议吗?

编辑:

我找到了以下链接来设置配置池:

I found the following link to set the configuration pool:

http://www.codingpedia.org/ama/tomcat-jdbc-connection-pool-configuration-for-production-and-d evelopment /

所以我试图在我的数据源中实现它:

so i tried to implement it in my datasource:

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
        destroy-method="close">

        <property name="driverClassName" value="com.mysql.jdbc.Driver" />

        <property name="url" value="jdbc:mysql://192.168.254.45:3306/7jogos" />
        <property name="password" value="..." />
        <property name="username" value="..." />


<!--      Configuration pool -->
        <property name="validationQuery" value="SELECT 1" />
        <property name="validationInterval" value="34000" />
        <property name="testOnBorrow" value="true" />
        <property name="removeAbandoned" value="true" />
        <property name="removeAbandonedTimeout" value="55" />


    </bean>

但我最终在validationInterval上收到错误说:

But i end up getting an error on validationInterval saying:

在此行找到多个注释:
- 在类'org.apache.commons.dbcp.BasicDataSource'中找不到属性'validationInterval'的setter

Multiple annotations found at this line: - No setter found for property 'validationInterval' in class 'org.apache.commons.dbcp.BasicDataSource'

推荐答案

我的编辑的答案是在我的bean中添加以下内容,其中包含连接数据:

The answer is on my edit that was to add the following in my beans that have the connection data:

<!--      Configuration pool -->
        <property name="validationQuery" value="SELECT 1" />
        <property name="validationInterval" value="34000" />
        <property name="testOnBorrow" value="true" />
        <property name="removeAbandoned" value="true" />
        <property name="removeAbandonedTimeout" value="55" />

我不知道为什么,但@PawełGłowacz的回答对我不起作用。
感谢您的帮助

I don't know why but @Paweł Głowacz 's answer didn't work for me. Thanks for your help guys

这篇关于首次登录时无法打开Hibernate Session进行交易的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆