I am using hibernate version 3.6.10.Final and hibernate-jmx.version 3.5.6-Final.. I have a 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
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.
Same with "normal" SQL.
The select clause is what you present as the query results. 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;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.