spring,使用HikariCP与c3p0,相同的代码,不同的结果。

huangapple go评论76阅读模式
英文:

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">

    &lt;property name=&quot;driverClassName&quot; value=&quot;#{meta[&#39;dataSource.driverClassName&#39;]}&quot; /&gt;
    &lt;property name=&quot;jdbcUrl&quot; value=&quot;#{meta[&#39;dataSource.url&#39;]}&quot; /&gt;
    &lt;property name=&quot;username&quot; value=&quot;#{meta[&#39;dataSource.username&#39;]}&quot; /&gt;
    &lt;property name=&quot;password&quot; value=&quot;#{meta[&#39;dataSource.password&#39;]}&quot; /&gt;
    &lt;property name=&quot;readOnly&quot; value=&quot;false&quot; /&gt;

    &lt;property name=&quot;idleTimeout&quot; value=&quot;#{meta[&#39;dataSource.maxIdleTime&#39;]}&quot; /&gt;
    &lt;property name=&quot;connectionTimeout&quot; value=&quot;30000&quot; /&gt;
    &lt;property name=&quot;maxLifetime&quot; value=&quot;1800000&quot; /&gt; 
    &lt;property name=&quot;maximumPoolSize&quot; value=&quot;#{meta[&#39;dataSource.maxPoolSize&#39;]}&quot; /&gt;
 
    &lt;property name=&quot;minimumIdle&quot; value=&quot;#{meta[&#39;dataSource.minPoolSize&#39;]}&quot; /&gt;
&lt;/bean&gt;

I expect to get the latest value with Hikari. Is there any problem with the configuration?

see https://github.com/brettwooldridge/HikariCP/issues/1522

答案1

得分: 1

以下是要翻译的内容:

这两个连接池可能具有不同的默认事务隔离级别值。

尝试添加
&lt;property name=&quot;transactionIsolation&quot; value=&quot;TRANSACTION_READ_COMMITTED&quot;

英文:

These 2 connection pools probably have different default values for the transaction isolation level.

Try adding
&lt;property name=&quot;transactionIsolation&quot; value=&quot;TRANSACTION_READ_COMMITTED&quot;

huangapple
  • 本文由 发表于 2020年1月6日 23:03:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/59614376.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定