• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Criteria API on fields without mapping

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Consider the following bean class:



Assume the hbm file have the mapping for the first 3 fields viz. id, name and yearOfBirth. Field 'age' is calculated based on the yearOfBirth and is set via setYearOfBirth() (Age is not stored in DB). I need a solution using Criteria API (org.hibernate.Criteria) to search on Person objects based on 'age' field. I'm trying the below code; but it raises an exception: org.hibernate.persister.entity.AbstractPropertyMapping.throwPropertyException (could not resolve property: age of: Person)


Any solutions ?

Thanks,
Binil
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All queries in Hibernate will generate SQL so they must be queries against mapped properties. There's no way of getting round that.

Why not change your query? Something like:

will be logically the same.
 
Benjamin Samuel
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My actual problem is little more complicated than this

So is it not possible to do the Criteria check on 'age' field?
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No. The steps Hibernate will take is to run a query then populate the properties of your object with the values in the result set. The Criteria will be used to generate the SQL, what you are after is logic applied after the query has been run.
 
Catch Ernie! Catch the egg! And catch this tiny ad too:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic