Hibernate Criteria API 和标量子查询
我想将 HQL 查询转换为 Criteria API,但我不知道是否可以使用 Criteria 编写相同的内容。
HQL 看起来像这样:
select distinct new DataTransferObject(property1, property2, ..., (select NVL(property3, null) from Table1 where property3 in elements(...) and ... ), property4, ..., (select .....), ...)
from Table2 as table2
left join table2.property5 as property5
(... more left joins ...)
where
.....
我开始像这样编写我的标准:
getSession().createCriteria(Table2.class, "table2")
.createAlias("table2.property5", "property5")
(...more createAlias...)
.add(Expression/Restriction
....
然后我创建了一个 ProjectionList,其中包含除那些(选择...)之外的所有构造函数参数。
最后:
criteria.setProjection( projectionList).setResultTransformer( Transformers.aliasToBean(DataTransferObject.class) ) .list()
我的问题是如何将这些(选择...)添加到projectionList ????
我试图实现的是在 select 子句(标量子查询)中创建子查询,而不是在 where 子句中,而是使用 Criteria API
I want to translate a HQL query to Criteria API but I don't know if it's possible to write the same thing with Criteria.
The HQL looks like this:
select distinct new DataTransferObject(property1, property2, ..., (select NVL(property3, null) from Table1 where property3 in elements(...) and ... ), property4, ..., (select .....), ...)
from Table2 as table2
left join table2.property5 as property5
(... more left joins ...)
where
.....
I started to write my Criteria like this:
getSession().createCriteria(Table2.class, "table2")
.createAlias("table2.property5", "property5")
(...more createAlias...)
.add(Expression/Restriction
....
I then created a ProjectionList with all the constructor arguments except those (select ...).
and at the end:
criteria.setProjection( projectionList).setResultTransformer( Transformers.aliasToBean(DataTransferObject.class) ) .list()
My question is how to add those (select ...) to the projectionList ????
What I try to achieve is to make a subquery in the select clause (scalar subqueries), not in the where clause, but using Criteria API
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论