简体   繁体   English

如何在休眠条件下编写多个子查询

[英]How to write multiple sub-query in Hibernate criteria

I am trying to write oracle subquery in Hibernate criteria but unable to do it. 我正在尝试使用Hibernate标准编写oracle子查询,但无法执行。 Can anyone help me to achieve this. 谁能帮助我实现这一目标。 Below is my oracle query. 下面是我的oracle查询。

SELECT a.id,
  b.address
FROM tableA a
INNER JOIN TABLE b
ON a.id       = b.id
WHERE mainId IN
  (SELECT bp.ptyID
  FROM bpTable bp,
    busHeaderbh bh
  WHERE bh.aid      = bp.aid
  AND bh.parentBID IN
    (SELECT bp.ptyID
    FROM bpTable bp,
      busHeaderbh bh
    WHERE bh.aid     = bp.aid
    AND bh.parentBID = 123
    UNION
    SELECT 123 FROM dual
    )
  UNION
  SELECT 123 FROM dual
  )
AND
GROUP BY a.id,
  b.credttm
ORDER BY a.id DESC;

Thanks in Advance. 提前致谢。

I have written one example for one to many relationship table you can get reference from it 我已经为一对多关系表编写了一个示例,您可以从中获得参考

Criteria person = session.getCurrentSession().createCriteria(Person.class).createAlias("personId", "personId");

person.add(Restrictions.disjunction().add(Restrictions.ilike("PersonFirstname",Search,MatchMode.ANYWHERE))
.add(Restrictions.ilike("personId.prop1",Search,MatchMode.ANYWHERE))
.add(Restrictions.ilike("personId.col1",Search,MatchMode.ANYWHERE))
.addOrder(Property.forName("colName").desc()
.addOrder(Property.forName("colName").asc());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM