When I set transaction isolation level in code, is it enforced in code or in DBMS?

1.2k views Asked by At

If I make a call like this in Java code:

connection.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);

is this enforced in code, by DBMS table/row-level locks, or either of those depending on the JDBC driver implementation?

Thanks!

2

There are 2 answers

2
Neo On BEST ANSWER

Isolation level is enforced by the database engine, not application code.

Here is a good resource on the subject if you are interested. Isolation Levels

0
Gab On

You're using the JDBC API which rely on the underlying JDBC driver implementation which rely on underlying RDBMS :

A JDBC driver might not support all transaction isolation levels. If a driver does not support the isolation level specified in an invocation of setTransactionIsolation, the driver can substitute a higher, more restrictive transaction isolation level. If a driver cannot substitute a higher transaction level, it throws a SQLException. Use the method DatabaseMetaData.supportsTransactionIsolationLevel to determine whether or not the driver supports a given level.

If you were using JTA API you would rely on underlying implementation fulfilling a JCA contract. The contract would also be implemented by the RDBMS in the case of relational database resource but could definitely be implemented differently (eg. using code) for a resource of another type (a JMS one for example).