You need another alias:
Code:
Criteria crit = session.createCriteria(User.class, "u");
crit.createAlias("school", "school", Criteria.INNER_JOIN);
crit.createAlias("school.city", "cty", Criteria.INNER_JOIN);
crit.add(Restrictions.eq("cty.id", cityId));
crit.setProjection(Projections.count("id"));
you can also use the chaining syntax to make your code more readable:
Code:
Criteria crit = session.createCriteria(User.class, "u")
.createAlias("school", "school", Criteria.INNER_JOIN)
.createAlias("school.city", "cty", Criteria.INNER_JOIN)
.add(Restrictions.eq("cty.id", cityId))
.setProjection(Projections.count("id"));