如何在休眠中组合来自多个子查询的列

how to combine columns from multiple subqueries in hibernate

我想在 HQL 中编写以下查询:

select v1.maxx, v2.maxx from
  (select max(id) maxx from mytable where my_column is not null ) v1,
  (select max(id) maxx from mytable where my_column is null) v2;

到目前为止我得到了以下信息:

  DetachedCriteria d1=DetachedCriteria.forClass(MyTable.class, "d1")
      .setProjection(Projections.max("id"))
      .add(Property.forName("myColumn").isNull();

  DetachedCriteria d2=DetachedCriteria.forClass(MyTable.class, "d2")
      .setProjection(Projections.max("id"))
      .add(Property.forName("myColumn").isNotNull();

但我很难将它们组合成一个条件对象。

这是我组合两个子查询的方法:

    Criteria criteria = Criteria.forClass(MyTable.class); 
    criteria.add(Subqueries.propertyEq("v1.maxx", d2));
    criteria.add(Subqueries.propertyEq("v2.maxx", d1));

无法找到如何在 SELECT 中包含多个子查询。所以我重写了 查询如下,它适用于 HQL:

select max(k.id), max(l.id) from myTable k, myTable l
  where k.myColumn is not null and l.myColumn is null;