Java hibernate 4.x,第二级Ehcache未按预期工作

Java hibernate 4.x,第二级Ehcache未按预期工作,java,spring,hibernate,ehcache,Java,Spring,Hibernate,Ehcache,这是我的配置: pom.xml: 使用hibernate和hibernate ehcache 4.2.8.Final版本 spring配置:我有以下hibernate属性 <prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</prop> <prop key="hibernate.cache.use_second_level_

这是我的配置:

pom.xml: 使用hibernate和hibernate ehcache 4.2.8.Final版本

spring配置:我有以下hibernate属性

<prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</prop>
<prop key="hibernate.cache.use_second_level_cache">true</prop>
日志:

我似乎不明白,当我最终手动更改数据库时,缓存是如何获取最新值的。日志表明,它也在从缓存中拾取这些更改的值


二级缓存是否接收到手动数据库更改,即数据库更改没有按照上述日志所示通过hibernate?或者是我做错了什么?

正如日志所示,对数据库执行SQL查询。数据来自数据库,而不是缓存。你看到的点击率是商店点击率


要从缓存中获取实体,请使用session.get,而不是查询

简体中文。。。api正在内部使用session.get。由于我有hibernate.show\u SQL=true属性集,您在日志中看到了SQL查询。另外,你所看到的点击量是商店点击量,这到底是什么意思?这不意味着它正在从缓存中获取值吗?谢谢你的帮助!您的所有where子句都是where systemconf0\属性,如?。这不可能是session.get的结果。对我来说,存储命中是指某个东西被存储在缓存中。没有从缓存中获取。你是对的,我使用的是HQL查询,而不是session.get。让我尝试使用session.get。
<ehcache>

    <diskStore path="java.io.tmpdir"/>

    <!--  cache setting for com.cisco.locker.entity.SystemConfig entity -->
    <cache name="com.cisco.locker.entity.SystemConfig"
        maxElementsInMemory="100"
        eternal="false"
        timeToIdleSeconds="600"
        timeToLiveSeconds="600"
        overflowToDisk="false"
        statistics="true"
        />

</ehcache>
@Entity
@Table(name = "system_config")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class SystemConfig implements Serializable {
...
}
First call: http://localhost:8080/test/getSystemConfigs
{
    "statusCode": "200",
    "statusMessage": "SUCCESS",
    "response": {
        "admin.lcu_status_polling_timer": "120",
        "admin.site_status_polling_interval": "15"
    }
}

Hibernate: select systemconf0_.ID as ID1_12_, systemconf0_.description as descript2_12_, systemconf0_.property as property3_12_, systemconf0_.value as value4_12_ from system_config systemconf0_ where systemconf0_.property like ?
2014-05-13 00:53:40,553 DEBUG net.sf.ehcache.Cache [http-bio-8080-exec-1]: com.cisco.locker.entity.SystemConfig cache - Miss
2014-05-13 00:53:40,561 DEBUG net.sf.ehcache.Cache [http-bio-8080-exec-1]: com.cisco.locker.entity.SystemConfig cache - Miss

Second call: http://localhost:8080/test/getSystemConfigs
{
    "statusCode": "200",
    "statusMessage": "SUCCESS",
    "response": {
        "admin.lcu_status_polling_timer": "120",
        "admin.site_status_polling_interval": "15"
    }
}

Hibernate: select systemconf0_.ID as ID1_12_, systemconf0_.description as descript2_12_, systemconf0_.property as property3_12_, systemconf0_.value as value4_12_ from system_config systemconf0_ where systemconf0_.property like ?
2014-05-13 00:53:48,037 DEBUG net.sf.ehcache.Cache [http-bio-8080-exec-2]: com.cisco.locker.entity.SystemConfigCache: com.cisco.locker.entity.SystemConfig store hit for com.cisco.locker.entity.SystemConfig#11
2014-05-13 00:53:48,037 DEBUG net.sf.ehcache.Cache [http-bio-8080-exec-2]: com.cisco.locker.entity.SystemConfigCache: com.cisco.locker.entity.SystemConfig store hit for com.cisco.locker.entity.SystemConfig#12


Third call – After manually changing value in DB "admin.site_status_polling_interval" from 15 to 10: http://localhost:8080/test/getSystemConfigs
{
    "statusCode": "200",
    "statusMessage": "SUCCESS",
    "response": {
        "admin.lcu_status_polling_timer": "120",
        "admin.site_status_polling_interval": "10"
    }
}

Hibernate: select systemconf0_.ID as ID1_12_, systemconf0_.description as descript2_12_, systemconf0_.property as property3_12_, systemconf0_.value as value4_12_ from system_config systemconf0_ where systemconf0_.property like ?
2014-05-13 00:54:08,738 DEBUG net.sf.ehcache.Cache [http-bio-8080-exec-4]: com.cisco.locker.entity.SystemConfigCache: com.cisco.locker.entity.SystemConfig store hit for com.cisco.locker.entity.SystemConfig#11
2014-05-13 00:54:08,738 DEBUG net.sf.ehcache.Cache [http-bio-8080-exec-4]: com.cisco.locker.entity.SystemConfigCache: com.cisco.locker.entity.SystemConfig store hit for com.cisco.locker.entity.SystemConfig#12