清除特定域类的休眠缓存 [英] clear hibernate cache of specific domain class

查看:110
本文介绍了清除特定域类的休眠缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有以下类:

$ p $ class Test {
字符串名称
static mapping = {
cache true
version false
}

目标是在数据库级别使用原生sql插入行,所以休眠不会识别这些变化。



有没有像 - > Test.clearCache?

解决方案

尽管这是一种不赞成使用的方式,但它更短,并且仍然有效。

  def sessionFactory //注入Hibernate sessionFactory 
sessionFactory.evict(clazz,id)
//或者驱逐所有类实例:
sessionFactory.evict(clazz)
pre>

文档是这里,用 Cache 来查看它的最新方式。


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?

解决方案

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.

这篇关于清除特定域类的休眠缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆