简体   繁体   English

提交后JDBC中的SERIALIZABLE事务保持SERIALIZABLE

[英]SERIALIZABLE Transaction in JDBC remains SERIALIZABLE after the commit

I have a problem with transactions in JDBC and Oracle. 我在JDBC和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). 问题是两个打印都显示:8(对应于Connection.TRANSACTION_SERIALIZABLE属性),但我认为它必须打印8和2 Connection.TRANSACTION_READ_COMMITTED属性)。 Any help? 有什么帮助吗?

You can see the commit() call as just a transaction boundary. 您可以将commit()调用视为事务边界。 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). 因此,在提交之后,您将处于新事务中,并且仍将处于相同的隔离级别(在这种情况下为SERIALIZABLE)。

By the way the JDBC specification dictates that calling commit() when auto-commit is true is illegal. 通过JDBC规范规定,当auto-commit为true时调用commit()是非法的。 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-- JavaDoc中的commit()提到了这一点,如果启用了自动提交,则会抛出异常: 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. 使用12.1 Oracle JDBC驱动程序将获得该行为。 Prior versions didn't throw an exception. 以前的版本没有引发异常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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