-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: QueryException: could not resolve property
PostPosted: Mon May 15, 2006 11:04 am 
Newbie

Joined: Mon May 15, 2006 10:30 am
Posts: 7
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)


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 15, 2006 1:50 pm 
Regular
Regular

Joined: Thu Jan 29, 2004 10:34 am
Posts: 52
Location: Austin, TX
read the manual section 15.4 about associations

device to brand is an association

Code:
criteria.add(Restrictions.eq("device.brand.id", {Long value}));


you can't plough through an association with the dot notation (eventhough it would be nice). it should be more like

Code:
sess.createCriteria(Device.class)
    .createCriteria("brand")
        .add(Restrictions.eq("id", {Long value}))
    .list();


Last edited by ravi on Thu May 18, 2006 7:39 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Tue May 16, 2006 3:52 am 
Newbie

Joined: Mon May 15, 2006 10:30 am
Posts: 7
Thnx! It works.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.