I have a Cat class and a Owner class. A cat has one owner but an owner can have many cats. What I want to query is get all owners who have a cat with blue eyes.
class Cat {
Owner owner; //referenced from Owner.id
String eyeColor;
}
class Owner {
List<Cat> catList;
}
I tried some codes but I really don't know what to do.
Criteria criteria = getCurrentSession().createCriteria(cat.getClass(), "cat");
criteria.createAlias("cat.owner", "owner");
criteria.add(Restrictions.eq("cat.eyeColor", "blue");