英文:
spring, use HikariCP VS c3p0 ,same code, different result
问题
以下是您要翻译的内容:
环境
HikariCP版本:HikariCP-java7 2.4.13
JDK版本:1.7.0_080
数据库:PostgreSQL
驱动程序版本:9.1-901.jdbc3
Spring中,使用HikariCP与c3p0,相同的代码,但结果不同
@Transactional
public Integer enableItem(Long id){
//将项目状态从0更改为1
Integer result = itemDao.enableItem(id);
//加载项目
//如果使用c3p0,项目状态是新值1
//但是使用Hikari,项目状态仍然是0
Item item = itemDao.findItemById(id);
return result;
}
在同一个事务中,首先将项目状态从0更改为1,然后读取最新的项目信息,如果使用c3p0,项目状态是新值1,但是使用Hikari,项目状态仍然是0
Hikari配置:
<bean id="dataSourceHikari" class="com.zaxxer.hikari.HikariDataSource" destroy-method="close">
<property name="driverClassName" value="#{meta['dataSource.driverClassName']}" />
<property name="jdbcUrl" value="#{meta['dataSource.url']}" />
<property name="username" value="#{meta['dataSource.username']}" />
<property name="password" value="#{meta['dataSource.password']}" />
<property name="readOnly" value="false" />
<property name="idleTimeout" value="#{meta['dataSource.maxIdleTime']}" />
<property name="connectionTimeout" value="30000" />
<property name="maxLifetime" value="1800000" />
<property name="maximumPoolSize" value="#{meta['dataSource.maxPoolSize']}" />
<property name="minimumIdle" value="#{meta['dataSource.minPoolSize']}" />
</bean>
我希望使用Hikari获得最新的值。配置是否存在问题?
请参阅https://github.com/brettwooldridge/HikariCP/issues/1522。
英文:
Environment
HikariCP version: HikariCP-java7 2.4.13
JDK version : 1.7.0_080
Database : PostgreSQL
Driver version : 9.1-901.jdbc3
spring, use HikariCP VS c3p0 ,same code, different results
@Transactional
public Integer enableItem(Long id){
//change item status from 0 to 1
Integer result = itemDao.enableItem(id);
//load item
//if c3p0 , item status is new value 1
// but Hikari, item status still is 0
Item item = itemDao.findItemById(id);
return result;
}
In the same transaction, first change the item status from 0 to 1, and then read the latest item information, if c3p0 , item status is new value 1 , but Hikari, item status still is 0
Hikari config:
<!-- Hikari Datasource -->
<bean id="dataSourceHikari" class="com.zaxxer.hikari.HikariDataSource" destroy-method="close">
<property name="driverClassName" value="#{meta['dataSource.driverClassName']}" />
<property name="jdbcUrl" value="#{meta['dataSource.url']}" />
<property name="username" value="#{meta['dataSource.username']}" />
<property name="password" value="#{meta['dataSource.password']}" />
<property name="readOnly" value="false" />
<property name="idleTimeout" value="#{meta['dataSource.maxIdleTime']}" />
<property name="connectionTimeout" value="30000" />
<property name="maxLifetime" value="1800000" />
<property name="maximumPoolSize" value="#{meta['dataSource.maxPoolSize']}" />
<property name="minimumIdle" value="#{meta['dataSource.minPoolSize']}" />
</bean>
I expect to get the latest value with Hikari. Is there any problem with the configuration?
答案1
得分: 1
以下是要翻译的内容:
这两个连接池可能具有不同的默认事务隔离级别值。
尝试添加
<property name="transactionIsolation" value="TRANSACTION_READ_COMMITTED"
英文:
These 2 connection pools probably have different default values for the transaction isolation level.
Try adding
<property name="transactionIsolation" value="TRANSACTION_READ_COMMITTED"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论