-->
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: class of
PostPosted: Wed May 14, 2008 12:18 pm 
Newbie

Joined: Tue Mar 14, 2006 3:58 pm
Posts: 3
I'm using Spring 2.5, Hibernate 3.2.6.ga and Oracle9Dialect. I'm trying to execute criteria query which fails with this message
Code:
org.hibernate.QueryException: could not resolve property: class of: com.nams.model.DeviceSummaryView


Here's the code: basically I have example class that may contain various properties some of which can have a wildcard

Code:
   private List<DeviceSummaryView> searchByCriteria(DeviceSummaryView example)
         throws IllegalAccessException, InvocationTargetException,
         NoSuchMethodException {
      assert(example != null);
      DetachedCriteria criteria = DetachedCriteria
            .forClass(DeviceSummaryView.class);
      Map<String, Object> propMap = BeanUtils.describe(example);
      Set<Entry<String, Object>> set = propMap.entrySet();
      for (Entry<String, Object> entry : set) {
         Object value = entry.getValue();
         if (value != null && String.class.isInstance(value))
         {
            if (value.toString().indexOf('%') >= 0)
            {
               criteria.add(Expression.like(entry.getKey(), value));
            } else
            {
               criteria.add(Property.forName(entry.getKey()).eq(value));
            }
         }
      }
      // DAO will simply call HibernateTemplate#findByCriteria
      return this.deviceSummaryViewDao.findByCriteria(criteria);
   }


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 14, 2008 12:57 pm 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
I think the problem is here:

Code:
Expression.like(entry.getKey(), value)


Whatever entry.getKey() is resolving to isn't actually a visible property in the class on which you are searching.

Can you debug and see what the value of getKey() is? Then check to see that the property exists in the class you are searching on, and that there is a public getter method?

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 14, 2008 1:30 pm 
Newbie

Joined: Tue Mar 14, 2006 3:58 pm
Posts: 3
Cameron! You are genius! But of course, the describe map would contain "class" property which in my code gets added as search criteria. After changing the following line:
Code:
if (value != null && String.class.isInstance(value))

to
Code:
if (!"class".equals(entry.getKey()) && value != null && String.class.isInstance(value))


Everything works as expected. Thanks a lot! Of course I do realize now that I have to pay attention to any other non-property fields my example class may have.


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.