Hello,
I am having a problem accessing a many2one property within a many2one property in my DeviceHeader class:
Code:
criteria.add(Restrictions.eq("device.brand.id", {Long value}));
When I try to test this code, I receive the following exception:
Code:
org.hibernate.QueryException: could not resolve property: device.brand.id...
It works when I do this:
Code:
criteria.add(Restrictions.eq("device.id", {Long value}));
But it fails again when I try this:
Code:
criteria.add(Restrictions.like("device.type", {String value}, MatchMode.ANYWHERE));
What could be the problem here and what can I do to solve it?
Details:
Hibernate version: 3.1.3 Mapping documents:Code:
<class name="com.icemobile.mymobile.data.domain.DeviceHeader" table="ice_device_header">
<id name="id" column="device_header_id" unsaved-value="0">
<generator class="increment" />
</id>
<many-to-one
name="device"
cascade="none"
column="device_id"
not-null="true"
class="com.icemobile.mymobile.data.domain.Device"
/>
.............
</class>
-------------------------------------
<class name="com.icemobile.mymobile.data.domain.Device" table="ice_device">
<id name="id" column="device_id" unsaved-value="0">
<generator class="increment" />
</id>
<property
name="type"
column="device_type"
not-null="true"
type="string"
length="64"
/>
<many-to-one
name="brand"
cascade="none"
column="brand_id"
not-null="true"
class="com.icemobile.mymobile.data.domain.Brand"
/>
...............
</class>
--------------------------------------------------------
<class name="com.icemobile.mymobile.data.domain.Brand" table="ice_brand">
<id name="id" column="brand_id" unsaved-value="0">
<generator class="increment" />
</id>
................................
Code between sessionFactory.openSession() and session.close():Code:
Criteria criteria = getSession().createCriteria(DeviceHeader.class);
criteria.add(Restrictions.eq("device.brand.id", {Long value}));
criteria.list();
Full stack trace of any exception that occurs:Code:
org.hibernate.QueryException: could not resolve property: device.brand.id of: com.icemobile.mymobile.data.domain.DeviceHeader
at org.hibernate.persister.entity.AbstractPropertyMapping.throwPropertyException(AbstractPropertyMapping.java:43)
at org.hibernate.persister.entity.AbstractPropertyMapping.toColumns(AbstractPropertyMapping.java:63)
at org.hibernate.persister.entity.BasicEntityPropertyMapping.toColumns(BasicEntityPropertyMapping.java:31)
at org.hibernate.persister.entity.AbstractEntityPersister.toColumns(AbstractEntityPersister.java:1257)
at org.hibernate.loader.criteria.CriteriaQueryTranslator.getColumns(CriteriaQueryTranslator.java:409)
at org.hibernate.loader.criteria.CriteriaQueryTranslator.getColumnsUsingProjection(CriteriaQueryTranslator.java:371)
at org.hibernate.criterion.SimpleExpression.toSqlString(SimpleExpression.java:45)
at org.hibernate.loader.criteria.CriteriaQueryTranslator.getWhereCondition(CriteriaQueryTranslator.java:316)
at org.hibernate.loader.criteria.CriteriaJoinWalker.<init>(CriteriaJoinWalker.java:86)
at org.hibernate.loader.criteria.CriteriaLoader.<init>(CriteriaLoader.java:67)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1531)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:298)