开发者社区> 问答> 正文

在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 2293 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
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
2022 DTCC-阿里云一站式数据库上云最佳实践 立即下载
云时代的数据库技术趋势 立即下载
超大型金融机构国产数据库全面迁移成功实践 立即下载