【问题标题】:Grails runtime exception: Could not open Hibernate session for transactionGrails 运行时异常:无法为事务打开 Hibernate 会话
【发布时间】:2011-10-31 16:55:33
【问题描述】:

我现在已经开发了一个 Grails Web 应用程序及其在 Tomcat 服务器上。我收到以下异常:

无法为事务打开 Hibernate Session;嵌套异常是 org.hibernate.TransactionException: JDBC begin failed:

当有人在一天中尝试使用 RESTful 服务时,第一次发生这种情况。 RESTful 服务在第一次刷新后可以正常工作,并且在发出后续请求时也可以正常工作。

Stacktrace 如下:

java.net.SocketException:连接重置

at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:96)

at java.net.SocketOutputStream.write(SocketOutputStream.java:136)

at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65)

at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:123)

at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3333)

at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1971)

at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2151)

at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2619)

at com.mysql.jdbc.ConnectionImpl.setAutoCommit(ConnectionImpl.java:4997)

at org.apache.commons.dbcp.DelegatingConnection.setAutoCommit(DelegatingConnection.java:371)

at org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.setAutoCommit(PoolingDataSource.java:328)

at $Proxy102.setAutoCommit(Unknown Source)

......


at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:200)

at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:291)

at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:775)

at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:704)

at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:897)

at java.lang.Thread.run(Thread.java:662)

非常感谢任何帮助。

谢谢

【问题讨论】:

标签: hibernate grails


【解决方案1】:

我们在 DataSource.groovy 中使用以下内容来解决该问题。查看链接@JamesA,前提是它似乎也有所需的信息。

dataSource {
  ...
  properties {
    ...     
    // when to test
    testOnBorrow = true
    testWhileIdle = true
    testOnReturn = false
    // what to test with
    validationQuery = "SELECT 1"
 }

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-11-16
    • 2019-09-27
    • 2017-07-08
    • 2020-07-15
    • 2011-06-13
    • 2017-06-19
    • 2017-09-04
    相关资源
    最近更新 更多