Q:

Comparing a Collection's Field - org.hibernate.QueryException: could not resolve property:

This answer clearly describes how to set a Restriction to compare where 2 properties are equal.
Given these 2 entities in that answer:
@Entity
public class Professor{
    K id;
    List<Student> students;
}

@Entity
public class Student{
    K profid;
    String name;
}

How would I write the following Restriction: where professor.students.name is "Kevin"?
I tried something like:
Criteria criteria = createCriteria(Professor.class);
criteria.add(Restrictions.eq("students.name", "Kevin")

but that failed with:
org.hibernate.QueryException: could not resolve property: 
     'students.name' of: Professor

A:

You need to add a alias to the collection first, like this
Criteria criteria = createCriteria(Professor.class);
criteria.addAlias("students", "s");
criteria.add(Restrictions.eq("s.name", "Kevin")

The Alias is needed because the Criteria API don't join automatically

