簡體   English   中英

Hibernate Criteria限制與投影alise

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM