Simulate the Transaction problem about dirty read, Non-repeatable reads, Phantom reads, Lost update in the H2, MySQL, Postgresql, SQLite,SQL Server databases by Spring Boot JUnit5.
Go to here to change your testing database type and you can custom your database ip or port.
# Database Type(h2 mysql postgresql sqlite sqlserver)database-type=h2
# Change to your custom mysql ip or portmysql-ip=localhost
mysql-port=3306
# Change to your custom postgresql ip or portpostgresql-ip=localhost
postgresql-port=5432
# Change to your custom sqlserver ip or portsqlserver-ip=localhost
sqlserver-port=4033
Use the JUnit 5 to test
Database Testing Result
H2
Isolation Level
Dirty Read
Unrepeatable Read
Phantom Read
Lost Update
DEFAULT
not occur
may occur
may occur
may occur
READ_UNCOMMITTED
may occur
may occur
may occur
may occur
READ_COMMITTED
not occur
may occur
may occur
may occur
REPEATABLE_READ
not occur
not occur
not occur
may occur
SERIALIZABLE
not occur
not occur
not occur
may occur
Isolation Level DEFAULT seems to be equal to READ_COMMITTED.
MySQL
Version: MySQL 5.7 InnoDB
Isolation Level
Dirty Read
Unrepeatable Read
Phantom Read
Lost Update
DEFAULT
not occur
not occur
may occur
may occur
READ_UNCOMMITTED
may occur
may occur
may occur
may occur
READ_COMMITTED
not occur
may occur
may occur
may occur
REPEATABLE_READ
not occur
not occur
may occur
may occur
SERIALIZABLE
not occur
not occur
not occur
not occur
Isolation Level DEFAULT seems to be equal to REPEATABLE_READ.
In the Lost Update problem, the SERIALIZABLE in Isolation Level must be retried with @Retryable; otherwise, it will throw LockAcquisitionException.
PostgreSQL
Version: PostgreSQL 13.2
Isolation Level
Dirty Read
Unrepeatable Read
Phantom Read
Lost Update
DEFAULT
not occur
may occur
may occur
may occur
READ_UNCOMMITTED
not occur
may occur
may occur
may occur
READ_COMMITTED
not occur
may occur
may occur
may occur
REPEATABLE_READ
not occur
not occur
not occur
not occur
SERIALIZABLE
not occur
not occur
not occur
not occur
Isolation Level DEFAULT seems to be equal to READ_COMMITTED.
In the Lost Update problem, the REPEATABLE_READ、SERIALIZABLE in Isolation Level must be retried with @Retryable; otherwise, it will throw LockAcquisitionException
SQLite
Isolation Level
Dirty Read
Unrepeatable Read
Phantom Read
Lost Update
DEFAULT
not occur
not occur
not occur
not occur
READ_UNCOMMITTED
not occur
not occur
not occur
not occur
SERIALIZABLE
not occur
not occur
not occur
not occur
SQLite supports only TRANSACTION_SERIALIZABLE and TRANSACTION_READ_UNCOMMITTED.
SQLite does not support concurrent writing, so you need to perform lock contention or retry writing.
SQL Server
Version: Microsoft SQL Server 2019 (RTM-CU10) (KB5001090) - 15.0.4123.1 (X64)
Isolation Level
Dirty Read
Unrepeatable Read
Phantom Read
Lost Update
DEFAULT
not occur
may occur
may occur
may occur
READ_UNCOMMITTED
may occur
may occur
may occur
may occur
READ_COMMITTED
not occur
may occur
may occur
may occur
REPEATABLE_READ
not occur
not occur
may occur
not occur
SERIALIZABLE
not occur
not occur
not occur
not occur
Isolation Level DEFAULT seems to be equal to READ_COMMITTED.
In the Lost Update problem, the REPEATABLE_READ、SERIALIZABLE in Isolation Level must be retried with @Retryable; otherwise, it will throw LockAcquisitionException.
Simulate the Transaction problem about dirty read, Non-repeatable reads, Phantom reads, Lost update in the H2, MySQL, Postgresql, SQLite,SQL Server databases by Spring Boot JUnit5.