I'm using Derby database and trying to create DB objects concurrently.
As we all know that the default isolation level in it is TRANSACTION_READ_COMMITTED.
But I don't want to allow even phantom reads with the DB and hence, I want to set the isolation level to TRANSACTION_SERIALIZABLE.
All I do is this bit of code.
if(jdbcTemplate.getDataSource().getConnection().getTransactionIsolation() == Connection.TRANSACTION_READ_COMMITTED) {
logger.info("The connection isolation is already TRANSACTION_READ_COMMITTED");
}
else {
logger.info("Please set the connection isolation to TRANSACTION_READ_COMMITTED");
}
jdbcTemplate.getDataSource().getConnection().setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
if(jdbcTemplate.getDataSource().getConnection().getTransactionIsolation() == Connection.TRANSACTION_SERIALIZABLE) {
logger.info("The connection isolation is now TRANSACTION_SERIALIZABLE");
}
As expected, I see the log as "The connection isolation is already TRANSACTION_READ_COMMITTED", but surprisingly I dont see the log for "The connection isolation is now TRANSACTION_SERIALIZABLE".
Also the exception that I was expecting occurs which confirms that the isolation level was not set to Serializable.