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 there 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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With