【问题标题】:Is the second-level cache support for caching the query result exclude the entity二级缓存是否支持缓存查询结果排除实体
【发布时间】:2010-12-23 02:31:08
【问题描述】:

普通查询方式:

Session sess=factory.getCurrentSession();
sess.beginTran....();

String hql="from Entity en where en......";
Query q=sess.createQuery(hql).setCacheble(true);
List<Entity> list=q.list();

在这种情况下,列表中的对象是“实体”。它们将被缓存。

但是我想知道如果 hql 是这样的,缓存是否会起作用:

hql="select new Result(count(xx),sum(xxx)) from Entity en ....";

class Result{
  long num;
  long sum;
  //constructor,getter and setter
}

现在,结果列表中对象的类型将是Result

List<Result> list=q.list();

我的问题是Result Object是否可以保存在二级缓存中

还有ResultTransformer怎么样?

q.setResultTransformer(AliasToEntityMapResultTransformer.INSTANCE);

此时q.list()中的对象类型为Map,这些地图也可以缓存吗?

【问题讨论】:

    标签: hibernate caching second-level-cache


    【解决方案1】:

    它当然适用于“new Result(...)”,但我不能 100% 确定 ResultTransformer。考虑到转换是在查询之后进行的,我看不出它为什么不这样做的原因。

    【讨论】:

      猜你喜欢
      • 2017-08-17
      • 2021-03-14
      • 1970-01-01
      • 2013-02-11
      • 2014-11-28
      • 2011-12-18
      • 1970-01-01
      • 2014-06-20
      • 1970-01-01
      相关资源
      最近更新 更多