[英]Hibernate Criteria Restriction with projection alise
我正在使用hibernate版本3.6.10.Final和hibernate-jmx.version 3.5.6-Final ..我有一个Hibernate Criteria
getCurrentSession().createCriteria(CustOrder.class)
.createAlias("custOrderSubStatusComments", "comment")
.setProjection(Projections.projectionList()
.add(Projections.groupProperty("id"))
.add(Projections.max("comment.id"))
.add(Projections.property("comment.value"), "val")
)
.add(Restrictions.eq("val", haltreason)).list();
这段代码给出了错误org.hibernate.QueryException: could not resolve property: val of: com.**.CustOrder
但是下面的代码工作正常。
getCurrentSession().createCriteria(CustOrder.class)
.createAlias("custOrderSubStatusComments", "comment")
.setProjection(Projections.projectionList()
.add(Projections.groupProperty("id"))
.add(Projections.max("comment.id"))
.add(Projections.property("comment.value"), "val")
)
.addOrder(Order.asc("val")).list();
我不明白为什么“val”在订购时有效,而在限制时无效。
与“普通”SQL相同。
select子句是您作为查询结果显示的内容。 例如我不能做以下事情......
select first_name f
from customer
where f='hello';
但我能做到......
select first_name f
from customer
where first_name='hello'
order by f;
如果可以,你将能够编写没有多大意义的表达式,例如......
select age + 10 as AgePlusTen
from Person
where AgePlusTen < 70;
如果你真的想,你可以使用一个子选择...
select * from (
select age + 10 as AgePlusTen
from Person
) where AgePlusTen < 70;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.