【发布时间】: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