glo*_*ing 5 java postgresql transactions h2
我正在为我的应用程序尝试不同的隔离级别,因为并发更新存在问题.我通过DataSource设置隔离级别,从中我获得数据库连接
BasicDataSource ds = new BasicDataSource();
ds.setDefaultTransactionIsolation(
Connection.TRANSACTION_REPEATABLE_READ)
/* more config ... */
ds.getConnection()
Run Code Online (Sandbox Code Playgroud)
对于postgres 9.3数据库,行上的并发更新会触发错误,这是预期的,并且根据标准SQL事务隔离级别的postgres文档,
ERROR: could not serialize access due to read/write dependencies among transactions
当将隔离级别设置为时,此错误将按预期消失Connection.TRANSACTION_READ_COMMITTED
尝试使用内存数据库中的H2重现此行为,隔离级别似乎不会改变我的unittest的结果.即使通过使用LOCK_MODE = 0设置数据库URL 并且/或者Connection.TRANSACTION_READ_UNCOMMITTED在并发更新时出现错误,也完全停用了隔离org.h2.jdbc.JdbcSQLException: Concurrent update in table "MyTable": another transaction has updated or deleted the same row
我的问题是:如何配置H2连接以使用特定的隔离级别,我对锁定模式或连接的任何更改都不会帮助我摆脱JdbcSQLException.
| 归档时间: |
|
| 查看次数: |
936 次 |
| 最近记录: |