开发者

clear hibernate cache of specific domain class

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜