代码之家  ›  专栏  ›  技术社区  ›  David Pfeffer

从HQL返回额外数据

  •  2
  • David Pfeffer  · 技术社区  · 14 年前

    我正在编写一个HQL查询,形式如下:

    from a where ... or exists (from b inner join b.c where ...) and ...
    

    a 从这个查询。不过,我还需要知道 exists 子句在我的代码中返回true或not。如果这是SQL,我会把它添加到select列表中。但是,即使我添加到HQL select子句中,它也会变成:

    select a, exists (from b inner join b.c where ...) as x from a where ... or x and ...
    

    抛弃我的价值 x

    有没有一种方法可以以某种方式获取类型化数据

    1 回复  |  直到 14 年前
        1
  •  3
  •   DanP    14 年前

    在我看来,你有两个选择:

    1) 将附加属性作为只读映射属性添加到实体中,使用 formula 映射以使用内联sql或udf派生值。

    2) 只获取你需要的数据 需要 aliastobeanresulttransformer 投射到包含感兴趣领域的强类型dto。

    你走哪条路真的取决于你,但我倾向于选择2,以免用不需要的字段污染你的域模型。