I created a deadlock situation by having 2 functions lock 2 rows in a mysql table in opposite orders. I have @Transactional on both functions. I also have an aspectj aspect on both functions that retries the failed one at most 2 more times.
After the deadlock, one thread succeeds and one fails. The failed one retries. So far so good. However, there are 2 problems after this point.
When the failed function was retried a second time, it reads the 2 rows again. However, the value for the first one is old and the second one is new.
At the end, the transaction fails because the transaction was already marked for rollback. So the @Transactional proxy is around the retry proxy. Is there a way to reverse the order? I tried to have the retry proxy inherit Ordered and set the order to Ordered.HIGHEST_VALUE and Ordered.LOWEST_VALUE but neither worked.