2014-06-10 91 views
1

我使用jpa2(eclipseLink),彈簧4.0.2,休眠4.3以下持久性配置。不知何故,查詢結果總是被緩存,即當我通過插入一個新行來更改另一個應用程序(例如直接sql)中的數據庫時,除非重新啓動服務器(此處爲tomcat7),否則不會在這裏返回新行。我在這裏錯過了什麼嗎?非常感謝!jpa 2.0與休眠持久性查詢緩存禁用

<?xml version="1.0" encoding="UTF-8"?> 

http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd」 版本= 「2.0」>

<persistence-unit name="test" transaction-type="RESOURCE_LOCAL"> 
    <description>soma</description> 
    <provider>org.hibernate.ejb.HibernatePersistence</provider> 
    <class>com.mycompany.model.MyModelClass</class> 

    <shared-cache-mode>NONE</shared-cache-mode> 
    <properties> 
     <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" /> 
     <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/dbname" /> 
     <property name="javax.persistence.jdbc.user" value="root" /> 
     <property name="javax.persistence.jdbc.password" value="password" /> 
     <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" /> 
     <property name="hibernate.hbm2ddl.auto" value="validate" /> 
     <property name="hibernate.show_sql" value="true" /> 
     <property name="hibernate.cache.use_second_level_cache" value="false"/> 
     <property name="hibernate.cache.use_query_cache" value="false"/> 
     <property name="javax.persistence.sharedCache.mode" value="NONE" /> 
     <property name="org.hibernate.cacheable" value="false" /> 

    </properties> 
</persistence-unit> 

+0

你在結果調用期間看到一個sql select嗎? –

+0

好的問題。從休眠生成爲「Hibernate:select ...」 – user3728006

回答

0

後我加入連接池,它現在一切正常;-)

<!-- pooling --> 
     <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" /> 
     <property name="hibernate.connection.provider_class" value="org.hibernate.connection.C3P0ConnectionProvider" /> 

     <property name="hibernate.c3p0.max_size" value="100" /> 
     <property name="hibernate.c3p0.min_size" value="0" /> 
     <property name="hibernate.c3p0.acquire_increment" value="1" /> 
     <property name="hibernate.c3p0.idle_test_period" value="300" /> 
     <property name="hibernate.c3p0.max_statements" value="0" /> 
     <property name="hibernate.c3p0.timeout" value="100" />