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 LevelsERROR: 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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With