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)
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.