简体   繁体   English

Hibernate Criteria限制与投影alise

[英]Hibernate Criteria Restriction with projection alise

I am using hibernate version 3.6.10.Final and hibernate-jmx.version 3.5.6-Final.. I have a Hibernate Criteria 我正在使用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();

This code is giving error org.hibernate.QueryException: could not resolve property: val of: com.**.CustOrder 这段代码给出了错误org.hibernate.QueryException: could not resolve property: val of: com.**.CustOrder

But the following code is working fine. 但是下面的代码工作正常。

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();

I don't understand why "val" is valid with ordering and invalid with restrictions. 我不明白为什么“val”在订购时有效,而在限制时无效。

Same with "normal" SQL. 与“普通”SQL相同。

The select clause is what you present as the query results. select子句是您作为查询结果显示的内容。 For example I cannot do the following... 例如我不能做以下事情......

select first_name f 
from customer
where f='hello';

But I can do... 但我能做到......

select first_name f 
from customer
where first_name='hello'
order by f;

If you could, you would be able to write expressions that don't make much sense, for example... 如果可以,你将能够编写没有多大意义的表达式,例如......

select age + 10 as AgePlusTen
from Person
where AgePlusTen < 70;

If you really wanted to, you could use a sub-select... 如果你真的想,你可以使用一个子选择...

select * from (
    select age + 10 as AgePlusTen
    from Person
) where AgePlusTen < 70;

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

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