JDBC Transaction Isolation Levels
The JDBC definition provides five transaction isolation levels. NuoDB supports a subset of these levels and provides alternative isolation levels. It also offers additional isolation mechanisms, not defined by JDBC, that can be used in place of unsupported levels. For more information, see Supported Transaction Isolation Levels.
| Other client drivers may not support isolation in the same way as the JDBC Driver. Refer to the documentation for each driver to identify the supported isolation levels. |
Isolation Levels
The following table describes the levels that are supported by NuoDB. The definition of read semantics are according to the JDBC specification. NuoDB’s use of consistent-read transactions provides the same or better semantics.
| ID | JDBC Constant | NuoDB JDBC Driver Support |
Description (Reads only) | Description (Updates) |
|---|---|---|---|---|
0 |
|
no |
No Transactions. |
|
1 |
|
no |
Dirty reads, non-repeatable reads and phantom reads are allowed. |
Use |
2 |
|
yes |
Dirty reads are prevented; non-repeatable reads and phantom reads can occur. |
Blocks on conflict; |
4 |
|
no |
Dirty reads are prevented; non-repeatable reads happen after writes; phantom reads can occur. |
Use |
8 |
|
yes |
Dirty reads, non-repeatable reads and phantom reads are prevented. |
No Blocking. |
7 |
|
yes |
NuoDB only. Native level. |
No blocking. |
The default isolation level is TRANSACTION_CONSISTENT_READ.
|
Configure Isolation Level
The isolation level can be configured using any of the following methods:
-
Configure the isolation level in the connection URL
To set the isolation property to all the connections created using the connection URL, specify
isolation=read_committed|consistent_read.For example:
jdbc:com.nuodb://localhost/test?isolation=read_committed -
Configure the isolation level in the java program using the
setTransactionIsolation()method:For example:
try (Connection dbConnection = dataSource.getConnection()) { dbConnection.setAutoCommit(false); dbConnection.setTransactionIsolation(Connection.READ_COMMITTED); ... } -
Configure the isolation level using Spring’s transactional support
Annotate a method with
org.springframework.transaction.annotation.Transactional.@Transactional(isolation = Isolation.READ_COMMITTED) public Account fetchAccount(String accountNumber) { ... return account; }Spring does not know about NuoDB
consistent-readisolation level.consistent-readis the default isolation level, so settingisolation = Isolation.DEFAULTin@Transactional, will defer toconsistent read.For example:
/* When default is specified, Spring defers to the database's default isolation. */ @Transactional(isolation = Isolation.DEFAULT) public Account fetchAccount(String accountNumber) { ... return account; }If
@Transactionalis applied to an interface, all the methods on that interface are transactional in every implementation.Spring and Spring Boot use different default implementations for transactions. Spring transactions are implemented using interface-based proxies by default and Spring Boot defaults to CGLIB (class-based) proxies.