Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting the transaction isolation level for a H2 via a DataSource

I'm trying different isolation levels for my application because of an issue with concurrent updates. I set the isolation level through a DataSource from which I get the database connection

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

With a postgres 9.3 database, concurrent updates on rows triggers an error, which is expected and 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 vanishes as expected when setting the isolation level to Connection.TRANSACTION_READ_COMMITTED

Trying to reproduce this behavior with an H2 in memory database, the isolation levels don't seem to change the outcome of my unittest. Even with deactivating isolation altogether with setting the database url with LOCK_MODE=0 and/or Connection.TRANSACTION_READ_UNCOMMITTED I get errors on concurrent updates org.h2.jdbc.JdbcSQLException: Concurrent update in table "MyTable": another transaction has updated or deleted the same row

My question would be: How do I configure the H2 connection to use a specific isolation level, none of my changes to the lock mode or the connection help me get rid of the JdbcSQLException.

like image 984
globalworming Avatar asked Nov 09 '22 20:11

globalworming


1 Answers

H2 is not supposed to be running in multi-threaded environment. You may use it for development purposes, etc. but on a threaded, heavy-load environment you should use an instance of a full-featured DBMS.

like image 111
Boris Schegolev Avatar answered Nov 15 '22 06:11

Boris Schegolev