CannotSerializeTransactionException and DeadlockLoserDataAccessException are deprecated as of Spring 6.0.3

This rule flags Java code that uses Spring’s deprecated locking-related exceptions CannotSerializeTransactionException and DeadlockLoserDataAccessException.

As of Spring Framework 6.0.3, these exceptions have been deprecated due to inconsistent semantics across JDBC drivers. Developers are advised to use CannotAcquireLockException instead, which offers a unified, framework-consistent way to handle pessimistic locking and transaction isolation failures.

The following example shows invalid usage that will be flagged:


import org.springframework.dao.CannotSerializeTransactionException;
import org.springframework.dao.DeadlockLoserDataAccessException;
public class InvalidLockingUsage {
    public void simulateCannotSerialize() {
    	throw new CannotSerializeTransactionException("Simulated serialization failure");
    }
    public void simulateDeadlock() {
    	throw new DeadlockLoserDataAccessException("Simulated deadlock");
    }
}

The following example shows valid migrated usage:


import org.springframework.dao.CannotAcquireLockException;
public class ValidLockingUsage {
    public void method() {
    	throw new CannotAcquireLockException("Simulated issue");
    }
}

For more information, see the following resources: