How can I retrieve a collection property using criteria Api
I want to retrieve a collection property using criteria
public class A {
private Collection<B> property
// getters and setters
}
public class B {
private int status
// getters and setters
}
My criteria code is as follows:
Criteria cr = getSession().createCriteria(A.class)
cr.createAlias("property", "prop")
cr.add(Restrictions.eq("prop.status", status));
cr.set开发者_运维知识库Projection(Projections.property("prop"));
cr.list();
It's obvious this code doesn't work I wanted to simply demonstrate my intentions. I know how to achieve this using HQL, but I have to use Criteria API. Is what I am aiming for even possible using Criteria ?
What wrong with this solution ?
Criteria cr = getSession().createCriteria(B.class);
cr.add(Restrictions.eq("status", status));
cr.list();
Unfortunately what I want to achieve is not possible with Hibernate Criteria. If someone needs something like that you should create a namedQuery , as awfull as that migh be to you or just use hql.
Peter
精彩评论