I need to translate the following query (which is tested and works) to use Criteria:
select distinct(c)
from Card c
join c.categories cat
join cat.allParents category
join category.allChildren child
join child.cards card
where c.id = card.id
and category = ?)
So far I have:
return getSession().createCriteria(Card.class, "c")
.setProjection(Projections.distinct(Projections.property("c")))
.createAlias("c.categories", "cat")
.createAlias("cat.allParents", "category")
.createAlias("category.allChildren", "child")
.createAlias("child.cards", "card")
.add(eqProperty("c.id", "card.id"))
.add(eq("category.id", cat.getId()));
which returns the exception "cannot resolve property: c of com.domain.Card"
if I take out the projection it works fine. anyone know of how to do distinct in the projection? Thanks.
|