5

在我的查询(查找)获得缓存会话关闭后,在一个新会话中,休眠在我通过随机写入 Sql 查询更改数据库后驱逐所有内容,我该如何阻止这种情况发生?我正在研究为很少改变的事物制定政策。

INFO    Executing [namedSqlQuery=dao.web_login, objs=[user1]] 
DEBUG   org.springframework.orm.hibernate3.SessionFactoryUtils user1- Opening Hibernate Session 
DEBUG   org.hibernate.impl.SessionImpl user1 - opened session at timestamp: 5511432318976000 
DEBUG   org.hibernate.impl.SessionFactoryImpl user1- evicting second-level cache: USERS_LOOKUP 
DEBUG   org.hibernate.impl.SessionFactoryImpl user1- evicting second-level cache: COUNTRY_LOOKUP

ecache.xml

 <cache name="query.oneHourPolicy"
           maxElementsInMemory="10000"
           eternal="false"
           timeToLiveSeconds="3600"
           diskPersistent="true"
           overflowToDisk="true"/>

春季休眠配置

 <prop key="hibernate.cache.use_second_level_cache">true</prop>
                <prop key="hibernate.cache.use_query_cache">true</prop>
                <prop key="hibernate.cache.provider_class">net.sf.ehcache.hibernate.SingletonEhCacheProvider</prop>
                <prop key="hibernate.cache.provider_configuration_file_resource_path">ehcache.xml</prop>
4

1 回答 1

3

发现休眠问题https://hibernate.onjira.com/browse/HHH-2224

我用波纹管测试:

在我的随机查询中

<sql-query name="random_write_query" callable="false">
        <synchronize table="USER"/>
        <synchronize table="USER_ADDRESS"/>
        {CALL PACKAGE.FUNCTION(?)}
</sql-query>

每当我调用上述内容并且它是数据库更改时,它只会使由 table = USER 或 USER_ADDRESS 同步的缓存无效

并且只有同步的随机读取查询或实体将被驱逐

<sql-query name="random_read_query">
         <synchronize table="USER"/>
         <synchronize table="USER_ADDRESS"/>
         <return-scalar column="USERNAME" type="string"/>
        <![CDATA[
            SELECT USERNAME FROM USER, USER_ADDRESS...
        ]]>
    </sql-query>
于 2012-08-22T17:13:35.657 回答