Question : A hibernate query question

I'm a newbie to Hibernate:
Suppose in my Dao methdod:
  @Override public List<client> getCilentRecord(int clientId) {
        List<client> clients = getHibernateTemplate().find(
           "from clientRecord where clientId =?", clientId);
  ...
createdDate field is defined as datetime in the hibernate table.

Now I want to display only most recent two days data and order by createdDate (DESC), how could I revise the HQL query above? Thanks for any hint.

Answer : A hibernate query question

There are 2 ways to go about this

1. Create a derived formula for the most recent 2 days data and define it as a property in the mapping file

<property name="last2days" type="datetime" formula="DATEDIFF(getdate(),-2')">
</property>
 List<client> clients = getHibernateTemplate().find(
          "from clientRecord where clientId =? and createdDate > last2days", clientId);

2. If this doesn't work out, use the Criteria object with SQLRestriction to put your native SQL query.

Random Solutions  
 
programming4us programming4us