我正在使用 mybatis 3.4.6 和 org.xerial:sqlite-jdbc 3.28.0。下面是我使用启用共享模式的内存数据库的配置
db.driver=org.sqlite.JDBC
db.url=jdbc:sqlite:file::memory:?cache=shared
db.url
根据这个测试类是正确的
我设法使用以下 mybatis 配置设置了正确的事务隔离级别,尽管根据我也报告的这个问题,属性 read_uncommitted 有一个错字
<environment id="${db.env}">
<transactionManager type="jdbc"/>
<dataSource type="POOLED">
<property name="driver" value="${db.driver}" />
<property name="url" value="${db.url}"/>
<property name="username" value="${db.username}" />
<property name="password" value="${db.password}" />
<property name="defaultTransactionIsolationLevel" value="1" />
<property name="driver.synchronous" value="OFF" />
<property name="driver.transaction_mode" value="IMMEDIATE"/>
<property name="driver.foreign_keys" value="ON"/>
</dataSource>
</environment>
这一行配置
<property name="defaultTransactionIsolationLevel" value="1" />
设置正确的PRAGMA read_uncommitted值的技巧
我很确定,因为我调试了初始化连接的底层代码并检查值是否已正确设置
但是通过上述设置,我的程序在读取时仍然会间歇性地遇到 SQLITE_LOCKED_SHAREDCACHE,根据下面屏幕截图红色矩形突出显示的描述,我认为它不应该发生。我想知道原因以及如何解决它,虽然这个错误的发生概率很低。
任何想法,将不胜感激!!
调试配置如下
===CONFINGURATION==============================================
jdbcDriver org.sqlite.JDBC
jdbcUrl jdbc:sqlite:file::memory:?cache=shared
jdbcUsername
jdbcPassword ************
poolMaxActiveConnections 10
poolMaxIdleConnections 5
poolMaxCheckoutTime 20000
poolTimeToWait 20000
poolPingEnabled false
poolPingQuery NO PING QUERY SET
poolPingConnectionsNotUsedFor 0
---STATUS-----------------------------------------------------
activeConnections 5
idleConnections 5
requestCount 27
averageRequestTime 7941
averageCheckoutTime 4437
claimedOverdue 0
averageOverdueCheckoutTime 0
hadToWait 0
averageWaitTime 0
badConnectionCount 0
===============================================================
附件:
例外如下
org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: org.apache.ibatis.transaction.TransactionException: Error configuring AutoCommit. Your driver may not support getAutoCommit() or setAutoCommit(). Requested setting: false. Cause: org.sqlite.SQLiteException: [SQLITE_LOCKED_SHAREDCACHE] Contention with a different database connection that shares the cache (database table is locked)
### The error may exist in mapper/MsgRecordDO-sqlmap-mappering.xml
### The error may involve com.super.mock.platform.agent.dal.daointerface.MsgRecordDAO.getRecord
### The error occurred while executing a query
### Cause: org.apache.ibatis.transaction.TransactionException: Error configuring AutoCommit. Your driver may not support getAutoCommit() or setAutoCommit(). Requested setting: false. Cause: org.sqlite.SQLiteException: [SQLITE_LOCKED_SHAREDCACHE] Contention with a different database connection that shares the cache (database table is locked)