I want to use the same function in DAO, suppose getBalances() with secure SERIALIZABLE isolation:

@Transactional(isolation=Isolation.SERIALIZABLE)
public List<Balance> getBalances() { ... }

in important business logic method:

public doVeryImportantFinancialChanges() {
.. complicated logic with multiple getEntries() calls, multiple SELECT/UPDATE...
}

but also I want to have unsafe "life view" of balances called every 1-2 seconds with SELECT only and acceptable broken integrity and all those nonrepeatable, phantom etc. data.

The problem is that my "life view" scheduled SELECT requestor uses getBalances() highly isolated function, and gets:

org.springframework.dao.DeadlockLoserDataAccessException: PreparedStatementCallback; SQL [SELECT * FROM ....]; Deadlock found when trying to get lock; try restarting transaction;

How to achieve double (safe-serializable and unsafe) access to same method getBalances() from different call sources?

有帮助吗?

解决方案

Try using @Transactional(propagation = Propagation.MANDATORY) on getBalances and define the isolation on the calling service.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top