Hibernate Grails在连接失败时自动重新打开连接

Hibernate Grails在连接失败时自动重新打开连接,hibernate,grails,jdbc,ingres,Hibernate,Grails,Jdbc,Ingres,我有一个Grails应用程序,通过域类与ingres数据库通信。当数据库崩溃或我在应用程序运行时重新启动数据库时,会出现异常: | Error Caused by: java.sql.SQLTransactionRollbackException: Connection failed. 当我每次访问数据库时都会出现此异常,尽管数据库从重启/崩溃中再次恢复 如何强制Grails/Hibernate重新创建连接或将其设置为自动重新创建连接 这是我的配置: dataSource { dbCr

我有一个Grails应用程序,通过域类与ingres数据库通信。当数据库崩溃或我在应用程序运行时重新启动数据库时,会出现异常:

| Error Caused by: java.sql.SQLTransactionRollbackException: Connection failed.
当我每次访问数据库时都会出现此异常,尽管数据库从重启/崩溃中再次恢复

如何强制Grails/Hibernate重新创建连接或将其设置为自动重新创建连接

这是我的配置:

dataSource {
    dbCreate = 'validate'
    url = "jdbc:ingres://xxx.xxx.xxx.xxx:II7/test"
    driverClassName = "com.ingres.jdbc.IngresDriver"
    username = "ingres"
    password = "ingres"
    jmxEnabled = true
    initialSize = 5
    maxActive = 50
    minIdle = 5
    maxIdle = 25
    maxWait = 10000
    maxAge = 10 * 60000
    timeBetweenEvictionRunsMillis = 5000
    minEvictableIdleTimeMillis = 60000
    validationQuery = "SELECT 1"
    validationQueryTimeout = 3
    validationInterval = 15000
    testOnBorrow = true
    testWhileIdle = true
    testOnReturn = true
    jdbcInterceptors = "ConnectionState"
    defaultTransactionIsolation = java.sql.Connection.TRANSACTION_READ_COMMITTED
}

java.sql.SQLTransactionRollbackException
表示,由于死锁或其他事务序列化失败,可能导致DB崩溃的最后一条语句被DB自动回滚

重启不能解决此问题,这可能是驱动程序特有的问题。似乎没有重置
SQLState
(可能仍然包含值“40”,或者供应商特定的值可能是什么)


也许主要的焦点应该是在应用程序级别上指出数据库崩溃的原因。在应用程序运行时重新启动DB服务器无论如何都是不好的做法

java.sql.SQLTransactionRollbackException表示,由于死锁或其他事务序列化失败,可能导致DB崩溃的最后一条语句被DB自动回滚

重启不能解决此问题,这可能是驱动程序特有的问题。似乎没有重置
SQLState
(可能仍然包含值“40”,或者供应商特定的值可能是什么)


也许主要的焦点应该是在应用程序级别上指出数据库崩溃的原因。在应用程序运行时重新启动DB服务器无论如何都是不好的做法

签出自动重新连接参数:

dataSource {
    url = "jdbc:mysql://localhost/databaseName?useUnicode=yes&characterEncoding=UTF-8&autoReconnect=true"
        }
其他可能有用的属性:

dataSource {
    pooled = true
    driverClassName = "com.mysql.jdbc.Driver"
    username = "secret"
    password = "santa"

   properties {
      maxActive = 50
      maxIdle = 25
      minIdle = 1
      initialSize = 1

      numTestsPerEvictionRun = 3
      maxWait = 10000

      testOnBorrow = true
      testWhileIdle = true
      testOnReturn = true

      validationQuery = "select now()"

      minEvictableIdleTimeMillis = 1000 * 60 * 5
      timeBetweenEvictionRunsMillis = 1000 * 60 * 5
   }
}

签出autoReconnect参数:

dataSource {
    url = "jdbc:mysql://localhost/databaseName?useUnicode=yes&characterEncoding=UTF-8&autoReconnect=true"
        }
其他可能有用的属性:

dataSource {
    pooled = true
    driverClassName = "com.mysql.jdbc.Driver"
    username = "secret"
    password = "santa"

   properties {
      maxActive = 50
      maxIdle = 25
      minIdle = 1
      initialSize = 1

      numTestsPerEvictionRun = 3
      maxWait = 10000

      testOnBorrow = true
      testWhileIdle = true
      testOnReturn = true

      validationQuery = "select now()"

      minEvictableIdleTimeMillis = 1000 * 60 * 5
      timeBetweenEvictionRunsMillis = 1000 * 60 * 5
   }
}

经过数小时的搜索和关键信息的丢失,这个问题很容易解决


在我问题中的初始配置中,数据源设置周围没有
properties{..}
group。genius Grails配置管理没有警告我需要它。加上它,一切正常,GORM可以从丢失的连接中恢复。

经过数小时的搜索和丢失关键信息后,问题很容易解决


在我问题中的初始配置中,数据源设置周围没有
properties{..}
group。genius Grails配置管理没有警告我需要它。加上它,一切正常,GORM可以从丢失的连接中恢复。

我没有在配置中使用
properties{}
部分(请参见问题)。有必要吗?
validationQuery=“select now()”
now()
在入口上不可用。改用
select 1
autoReconnect
URL参数对Ingres JDBC驱动程序不可用。但它对mySQL有效。我没有在配置中使用
properties{}
部分(请参见问题)。有必要吗?
validationQuery=“select now()”
now()
在入口上不可用。改用
select 1
autoReconnect
URL参数对Ingres JDBC驱动程序不可用。但它对mySQL有效。