0

I have encountered an issue, that is, tomcat jdbc pool cooperating with hibernate caches query results, but I have banned hibernate's cache.

But when I switch jdbc pool to DBCP, the issue get disappeared. So I ensure that there's a query result cache in tomcat jdbc pool, but I haven't found any documents on this issue.

Could someone tell me how to close the query cache in tomcat jdbc pool ? it runs in tomcat-jdbc-7.0.47 and there is the configuration below.

<bean id="dataSource" class="org.apache.tomcat.jdbc.pool.DataSource" destroy-method="close">
    <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
    <property name="url"
              value="jdbc:mysql://192.168.1.104:3306/uip_test_1?useUnicode=true&amp;characterEncoding=UTF8&amp;zeroDateTimeBehavior=convertToNull"/>
    <property name="username" value="root"/>
    <property name="password" value="root"/>
    <property name="defaultAutoCommit" value="false"/>
    <!--<property name="initialSize" value="10" />-->
    <property name="maxActive" value="40"/>
    <property name="maxIdle" value="10"/>
    <property name="maxWait" value="60000"/>
    <property name="testOnBorrow" value="true"/>
    <property name="timeBetweenEvictionRunsMillis" value="3600000"/>
    <property name="testWhileIdle" value="true"/>
    <property name="validationQuery" value="select 1 from dual"/>
</bean>
Mr rain
  • 983
  • 5
  • 13
  • 27
  • There's a statement [in the Tomcat 7 connection pool documentation](http://tomcat.apache.org/tomcat-7.0-doc/jdbc-pool.html) that 'you can use interceptors to gather query stats, cache session states, reconnect the connection upon failures, retry queries, cache query results, and so on', which implies it doesn't do that by default. – user207421 Feb 18 '14 at 03:59
  • but actually, it did, it cached. – Mr rain Feb 18 '14 at 04:02
  • Can you post a small code sample that explains why you think it cached the result? – Pace Feb 18 '14 at 04:06
  • I changed the value in database, but, it didn't change when I query it out using tomcat jdbc – Mr rain Feb 18 '14 at 04:17
  • 1
    Ok. So that isn't a query cache but an entity cache. It could be some kind of isolation issue. Are you using the exact same database with Tomcat's pool and DBCP's pool? Even if you are it is possible that Tomcat's pool is setting a different isolation level on the underlying database than DBCP is. Are you setting defaultTransactionIsolation on either pool? Also, how are you performing your test query? Are you writing the data and then querying it in the same transaction or querying it from a different transaction? Are you committing your transaction before the query? – Pace Feb 18 '14 at 12:24

0 Answers0