简体   繁体   English

选择并更新hibernate缓存表

[英]Select and Update hibernate caching table

I'm just implementing the hibernate query cache. 我只是实现了hibernate查询缓存。 I just want to know the behavior/working of hibernate cache concept if I do a manual update and hibernate update on the table which has been cached already. 我只是想知道hibernate缓存概念的行为/工作,如果我在已经缓存的表上进行手动更新和hibernate更新。

Scenario: 场景:

  1. Select cache Table A 选择缓存表A.
  2. Update Table A (manually or hibernate) 更新表A(手动或休眠)
  3. Select Table A again 再次选择表A.

The changes are reflected or I need to restart the server. 反映的更改或我需要重新启动服务器。

Below are my hibernate properties 下面是我的hibernate属性

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

If you always update the TableA through Hibernate API, then the Query Cache might get invalidated. 如果您始终通过Hibernate API更新TableA ,则查询缓存可能会失效。

  1. With HQL, you are safe because Hibernate can extract the updated tables and invalidate the query cache regions that might get stale. 使用HQL,您是安全的,因为Hibernate可以提取更新的表并使可能变得陈旧的查询缓存区域无效。

  2. With native queries, all Query Cache regions are invalidated whenever you run a native SML statement. 使用本机查询,每当运行本机SML语句时,所有查询缓存区域都将失效。 To restrict the affected Query Cache regions, you need to specify a Synchronization as follow: 要限制受影响的查询缓存区域,您需要指定Synchronization ,如下所示:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM