开发者

clear hibernate cache of specific domain class

开发者 https://www.devze.com 2023-03-18 02:08 出处:网络
Imagine i have following class: class Test { String name static mapping = { cache true version false } The goal would be to insert rows using native sql on the database level so hibernate wouldn\'t

Imagine i have following class:

class Test {
   String name    
   static mapping = {
      cache true
      version false
}

The goal would be to insert rows using native sql on the database level so hibernate wouldn't recognize those changes. how can i notifiy hibnerate about this new rows?

Is the开发者_JAVA技巧re something like -> Test.clearCache?


This answer is a little bit old... the evict method is deprecated... you can use

sessionFactory.cache.evictEntityRegion(Class.name)

this worked for me... just google the class and you will find all methods...


Though it's a deprecated way, it's shorter and still works.

def sessionFactory // inject Hibernate sessionFactory
sessionFactory.evict(clazz, id)
// or evict all class instances:
sessionFactory.evict(clazz)

Documentation is here, see it for the up-to-date way with Cache.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号