Clear hibernation cache for a specific domain class

Imagine that I have the following class:

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

The goal is to insert rows using native sql at the database level so that sleep mode does not recognize these changes. how can i notifiy hibnerate about these new lines?

Is there something like β†’ Test.clearCache?

+6
source share
2 answers

Although this is an obsolete method, it is shorter and still works.

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

The documentation is here , see it up to date with Cache .

+6
source

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

 sessionFactory.cache.evictEntityRegion(Class.name) 

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

+7
source

Source: https://habr.com/ru/post/892328/


All Articles