开发者社区> 问答> 正文

在Spring3.2和Hibernate4.2.8集成测试的时候出现数据库连不上的错误。。。

org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is org.hibernate.exception.JDBCConnectionException: Could not open connection
at org.springframework.orm.hibernate4.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:514).....

把数据源换成c3p0也不行,求大神!!

展开
收起
小旋风柴进 2016-03-16 18:14:52 2290 0
1 条回答
写回答
取消 提交回答
  • Could not open Hibernate Session for transaction;

    应该是数据库连接未设置自动重连的属性或者是数据库的jdbc驱动不能支持重连

    你检查下你的连接池属性配置

    mysql的重连autoReconnect参数不能使连接重连 
    c3p0连接池支持重连;重连参数是: 
    idleConnectionTestPeriod 设置空闲连接测试周期 
    preferredTestQuery : 设置一查询语句,用于重连测试 
    testConnectionOnCheckin设置为true 
    testConnectionOnCheckout设置为true 
    testConnectionOnCheckout设置为true
    2019-07-17 19:04:18
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
The Reactive Cloud Native Arch 立即下载
集成智能接入网关APP:优化企业级移动办公网络 立即下载
云效助力企业集成安全到DevOps中 立即下载