简体   繁体   中英

SERIALIZABLE Transaction in JDBC remains SERIALIZABLE after the commit

I have a problem with transactions in JDBC and Oracle. I have the following code:

con.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
con.setAutoCommit(true);
System.out.println(con.getTransactionIsolation());
con.commit();
System.out.println(con.getTransactionIsolation());

the problem is that both prints show: 8 (corresponding to the Connection.TRANSACTION_SERIALIZABLE attribute) but I think that it would have to print 8 and 2 Connection.TRANSACTION_READ_COMMITTED attribute). Any help?

You can see the commit() call as just a transaction boundary. So after the commit you will be in a new transaction and you will still be in the same isolation level (SERIALIZABLE in this case).

By the way the JDBC specification dictates that calling commit() when auto-commit is true is illegal. This is mentioned in the JavaDoc for commit() which will throw an exception if auto-commit is enabled: http://docs.oracle.com/javase/8/docs/api/java/sql/Connection.html#commit--

You will get that behavior using the 12.1 Oracle JDBC driver. Prior versions didn't throw an exception.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM