【问题标题】:Select and Update hibernate caching table选择和更新休眠缓存表
【发布时间】:2015-10-13 15:48:24
【问题描述】:

我只是在实现休眠查询缓存。如果我对已经缓存的表进行手动更新和休眠更新,我只想知道休眠缓存概念的行为/工作。

场景:

  1. 选择缓存表 A
  2. 更新表 A(手动或休眠)
  3. 再次选择表 A

更改已反映或我需要重新启动服务器。

下面是我的休眠属性

<property name="hibernateProperties">
    <value>
    hibernate.dialect=org.hibernate.dialect.DB2Dialect
        hibernate.format_sql=true
        hibernate.show_sql=false
        hibernate.cache.use_second_level_cache=true
        hibernate.cache.use_query_cache=true
        hibernate.generate_statistics=true
        org.hibernate.cache.ehcache.configurationResourceName=/ehcache.xml
        hibernate.cache.region.factory_class=org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory
    </value>
</property>

【问题讨论】:

    标签: java hibernate caching orm ehcache


    【解决方案1】:

    如果您总是通过 Hibernate API 更新 TableA,那么 Query Cache 可能会失效。

    1. 使用 HQL,您是安全的,因为 Hibernate 可以提取更新的表并使可能过时的查询缓存区域无效。

    2. 对于本机查询,只要您运行本机 SML 语句,所有查询缓存区域都会失效。要限制受影响的查询缓存区域,您需要指定Synchronization,如下所示:

      session.createSQLQuery(
          "update TableA set name = '\"'||name||'\"' "
      )
      .addSynchronizedEntityClass(TableA.class)
      .executeUpdate()
      

    【讨论】:

      猜你喜欢
      • 2015-01-09
      • 2013-04-24
      • 2017-01-16
      • 2011-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-13
      相关资源
      最近更新 更多