I am working on Java Spring Hibernate Project with mysql.
I am trying to do some kind of insertion in a cascade. Jobs are placed on the cluster, so they can occur almost simultaneously, so there is a problem with locking.
I have this error:
Deadlock detected while trying to get a lock; try restarting the transaction
I found here that there is @RetryTransaction for Spring developper. The setting method is here .
They say that:
The method class must be gossiped (either at build time or at run time) using the AspectJ compiler with the RetryTransactionAspect aspect (included in the JAR file for dellroad-stuff).
What does it mean?
But I can't get it to work. It never restarts a transaction. What am I missing?
Thanks!
@Override @RetryTransaction @Transactional public void save(AnalyseResult analyseResult){ @SuppressWarnings("deprecation") final int attempt = RetryTransactionAspect.getAttempt(); System.out.println("#############"); System.out.println("Retry Transact : "+attempt); System.out.println("#############"); analyseResultDao.save(analyseResult); }
In my BeanConfig.xml:
<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>
java spring mysql hibernate deadlock
Zhefrench
source share