Hi!
I have four tables:
car,
owner,
city, and
country and car->owner, owner->city, city->country are all "Many-to-one" and I configured them the same way, for example the Car.hbm.xml:
Code:
<many-to-one class="Owner" column="ID_USER" name="owner"/>
Now I want to search the cars in one country, for example USA(the id in db is 2), then I create criteria as following:
Code:
DetachedCriteria criteria = DetachedCriteria.forClass(Car.class);
criteria.add(Expression.eq("owner.city.country.id", 2l);
But when I search by the created creteria, one Exception says:
org.springframework.orm.hibernate3.HibernateQueryException: could not resolve property: owner.city.country.id of: Car;
nested exception is org.hibernate.QueryException: could not resolve property: owner.city.country.id of: Car
org.hibernate.QueryException: could not resolve property: owner.city.country.id of: Car at org.hibernate.persister.entity.AbstractPropertyMapping.propertyException(AbstractPropertyMapping.java:44)
at org.hibernate.persister.entity.AbstractPropertyMapping.toColumns(AbstractPropertyMapping.java:59)
at org.hibernate.persister.entity.BasicEntityPropertyMapping.toColumns(BasicEntityPropertyMapping.java:31)
at org.hibernate.persister.entity.AbstractEntityPersister.toColumns(AbstractEntityPersister.java:1350)
at org.hibernate.loader.criteria.CriteriaQueryTranslator.getColumns(CriteriaQueryTranslator.java:434)
at org.hibernate.loader.criteria.CriteriaQueryTranslator.getColumnsUsingProjection(CriteriaQueryTranslator.java:394)
at org.hibernate.criterion.SimpleExpression.toSqlString(SimpleExpression.java:45)
at org.hibernate.loader.criteria.CriteriaQueryTranslator.getWhereCondition(CriteriaQueryTranslator.java:334)
at org.hibernate.loader.criteria.CriteriaJoinWalker.<init>(CriteriaJoinWalker.java:82)
at org.hibernate.loader.criteria.CriteriaLoader.<init>(CriteriaLoader.java:67)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1550)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
at org.springframework.orm.hibernate3.HibernateTemplate$37.doInHibernate(HibernateTemplate.java:988)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:366)
at org.springframework.orm.hibernate3.HibernateTemplate.findByCriteria(HibernateTemplate.java:978)
at org.springframework.orm.hibernate3.HibernateTemplate.findByCriteria(HibernateTemplate.java:971)
Could any one help to resolve this?
Thanks a lot!