Set transaction isolation level for H2 through a data source

I am trying to use different isolation levels for my application due to a problem with concurrent updates. I set the isolation level through the DataSource from which I get the database connection

BasicDataSource ds = new BasicDataSource(); ds.setDefaultTransactionIsolation( Connection.TRANSACTION_REPEATABLE_READ) /* more config ... */ ds.getConnection() 

When using postgres 9.3 database, simultaneous updates in rows trigger an error, which is expected according to the postgres documentation on Standard SQL Transaction Isolation Levels
ERROR: could not serialize access due to read/write dependencies among transactions This error disappears as expected when setting the isolation level to Connection.TRANSACTION_READ_COMMITTED

Trying to reproduce this behavior with an H2 database in memory, isolation levels do not seem to change the result of my unittest. Even when deactivating isolation in general with setting the database URL with LOCK_MODE = 0 and / or Connection.TRANSACTION_READ_UNCOMMITTED I get errors while updating org.h2.jdbc.JdbcSQLException: Concurrent update in table "MyTable": another transaction has updated or deleted the same row

My question is: How do I configure an H2 connection to use a certain isolation level, none of my changes in lock mode or connection help me get rid of JdbcSQLException.

+5
source share
1 answer

H2 is not intended to work in a multi-threaded environment. You can use it for development purposes, etc., but in a multi-threaded environment with a heavy load, you should use an instance of a fully functional DBMS.

0
source

Source: https://habr.com/ru/post/1242163/


All Articles