【问题标题】:Hibernate 4 default transaction timeout valueHibernate 4 默认事务超时值
【发布时间】:2015-01-15 09:24:27
【问题描述】:

我收到此错误:

2014-11-14 17:39:44 [WARN]SqlExceptionHelper:143    SQL Error: 0, SQLState: 08S01
2014-11-14 17:39:44 [ERROR]SqlExceptionHelper:144   Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
2014-11-14 17:39:44 [ERROR]BackupService:245    org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is org.hibernate.exception.JDBCConnectionException: Could not open connection

似乎 Hibernate 对我的工作有一个小的事务超时,但我找不到默认超时值是多少。我在hibernate文档中也没有找到它,我找到了如何更改它,但不是默认值。

这是我的休眠配置:

<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="packagesToScan">
            <list>
                <value>com.test.db.entity</value>
            </list>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>
                <prop key="hibernate.show_sql">false</prop>             
                <prop key="hibernate.bytecode.use_reflection_optimizer">false</prop>
                <prop key="hibernate.cglib.use_reflection_optimizer">true</prop>
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                <prop key="hibernate.search.autoregister_listeners">false</prop>
                <prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</prop>         
            </props>
        </property>
</bean>

您知道使用此配置的休眠事务的默认超时值是多少吗?

【问题讨论】:

  • 你的连接字符串是什么?您尚未在 hibernateProperties 中指定 hibernate.connection.url 属性。
  • 这与交易无关。在最后一个错误行的末尾,它显示Could not open connection
  • 您是否尝试过以服务器模式启动数据库?能启动吗?
  • 是的,它可以工作,只是在需要大约 5 分钟的操作结束时它会中断。可能是因为main(5分钟)方法有@Transaction注解?
  • 我强调该应用程序运行良好,只是这个操作每次运行都会出现这个问题。

标签: java mysql spring hibernate timeout


【解决方案1】:

我遇到了同样的例外。我用谷歌搜索发现你的问题没有答案:)

我在 Weblogic 控制台上的“mydomain->Configuration->JTA”上将“超时秒数:”从 300 更改为 1000(可能会增加更多,这取决于您的事务超时),或者在您的应用程序服务器上增加 JTA 超时。

然后,对于 hibernate.cfg.xml 你可以检查这个答案:Hibernate/MySQL Connection Timeout

它有效。

【讨论】:

    猜你喜欢
    • 2010-11-23
    • 2018-01-22
    • 2012-07-17
    • 2017-12-25
    • 2012-05-05
    • 2021-01-24
    • 1970-01-01
    • 2015-02-03
    • 1970-01-01
    相关资源
    最近更新 更多