I am trying to use Criteria API in following scenario:
- I have two tables, 
ScheduleandRoute(with their classes and mappings). Routehas many-to-one relationship withSchedule.Routehas an integer propertysequence.
Now I need to fetch all those Schedule objects whose associated Route objects fulfill the following condition:
route.sequence=no. of all Route objects associated with the given Schedule object
I have tried the following Criteria code for it:
Criteria crit = getSession().createCriteria(getPersistentClass())
    .createCriteria("routes", "route")
    .setProjection(Projections.projectionList()
    .add( Projections.rowCount(), "routeCount"))
    .add(Restrictions.not(Restrictions.ltProperty("route.sequence", "routeCount")));
But it generates the following sql:
select count(*) as y0_ 
from schedule this_
inner join route route1_ on this_.ID=route1_.scheduleId
where route1_.sequence<y0_
and throws the following error:
Unknown column 'y0_' in 'where clause'
Please help me if you have any suggestions.