Criteria, how to access a subclass property
criteria, criteria-api, hibernate, java
Solution
You have to create an alias for the subclass property to be able to access it.
Take a look at section 15.4 of the following manual http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/querycriteria.html
Problem
weirdly I cannot find something simple about this, I've got 2 entity, one inside an other and my question is how can I access a property from the sub-entity? entity 1 ``` @Getter @Setter @Entity public class ObjectA{ String name; String surname; ObjectB B; } ``` entity 2 ``` @Setter @Getter @Entity ObjectB{ String family; String range; } ``` what I want is to access familly and range with a criteria search, so I made this : ``` public List<ObjectA> search(String name, String surname, String family, String range) { Criteria c = HibernateUtil.getSessionFactory().getCurrentSession().createCriteria(ObjectA.class, "a"); if (!name.equals("")) { c.add(Restrictions.eq("a.name", name)); } if (!surname.equals("")) { c.add(Restrictions.eq("a.surname", surname)); } if (!family.equals("")) { c.add(Restrictions.eq("a.B.family", family)); } if (!range.equals("")) { c.add(Restrictions.eq("a.B.range", range)); } return c.list(); ``` } name and surname can be accessed but family and range cannot. 'could not resolve property' What should I do? thanks =D