并发事务导致我的SQL语句失败。 我尝试使用[此] dellroad-stuff1,但似乎被忽略了。 我正在使用Spring 3和Hibernate 4。
错误信息:
15:32:11,331 WARN SqlExceptionHelper:145 - SQL Error: 1213, SQLState: 40001
15:32:11,331 ERROR SqlExceptionHelper:147 - Deadlock found when trying to get lock; try restarting transaction
15:32:11,334 INFO AbstractBatchImpl:195 - HHH000010: On release of batch it still contained JDBC statements
重试交易失败的注释函数:
@Override
@RetryTransaction
@Transactional
public void save(AnalyseResult analyseResult) {
final int attempt = RetryTransactionAspect.aspectOf().getAttemptNumber();
System.out.println("#############");
System.out.println("Retry Transact : "+attempt);
System.out.println("#############");
analyseResultDao.save(analyseResult);
}
Beans.xml文件
<!-- An @AspectJ aspect will be interpreted as an aspect by Spring AOP and beans
in the context will be advised accordingly -->
<aop:aspectj-autoproxy proxy-target-class="true" />
<bean id="hibernateExceptionTranslator" class="org.springframework.orm.hibernate4.HibernateExceptionTranslator"/>
<bean class="org.dellroad.stuff.spring.RetryTransactionAspect" factory-method="aspectOf">
<property name="persistenceExceptionTranslator" ref="hibernateExceptionTranslator"></property>
<property name="maxRetriesDefault" value="4"></property>
<property name="initialDelayDefault" value="25"></property>
<property name="maximumDelayDefault" value="5000"></property>
</bean>