jpa 2.0与hibernate持久性查询缓存禁用

时间:2014-06-10 23:16:48

标签: spring caching jpa

我在jpa2(eclipseLink),spring 4.0.2,hibernate 4.3中使用以下持久性配置。不知何故,查询结果总是被缓存,即当我通过插入新行更改另一个应用程序(例如直接sql)中的数据库时,除非我重新启动服务器(这里是tomcat7),否则不会在此处返回新行。我在这里错过了什么吗?非常感谢!

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

http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd”     版本= “2.0” &GT;

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

1 个答案:

答案 0 :(得分: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" />