Select and update hibernate caching table

I am just implementing a hibernate cache. I just want to know the behavior / operation of the hibernation cache concept if I update manually refresh and hibernate on an already encrypted table.

Scenario:

  • Select cache table A
  • Refresh table A (manually or hibernate)
  • Select table A again

The changes are reflected or I need to restart the server.

Below are my hibernate properties

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

      

+3


source to share


1 answer


If you always update the API TableA

through Hibernate, then the Query Cache may become invalid.



  • With HQL, you can be sure that Hibernate can fetch updated tables and invalidate query cache areas that might be out of date.

  • When using native queries, all areas of the query cache are invalidated whenever you run a native SML statement. To limit the affected areas of the query cache, you need to specify Synchronization

    as follows:

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

0


source







All Articles