Announcement Announcement Module
Collapse
No announcement yet.
HQL problem: db2 date function Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • HQL problem: db2 date function

    hi,

    i have a HQL problem using spring 2.0-rc3 and hibernate3, and db2 v8.1.

    my code in dao class is here.

    Code:
    public List getAccountList(Date d) {
    	return getHibernateTemplate().find("from test.Account account where date(account.createTime + 7 days) < ?", d);
    }
    i got HibernateQueryException,

    org.springframework.orm.hibernate3.HibernateQueryE xception: unexpected token: days near line 1, column 99 [from test.Account account where date(account.createTime + 7 days) < ?];

    how can i use db2 "date" function in HQL?

    regards,
    aquaruis

  • #2
    Equivalent code

    Hi aquaruis,

    You cannot use a database-specific function in HQL. The following code, which I believe to be equivalent, works using HQL and no database-specific functionality:

    Code:
    public List getAccountList(Date d) {
    		
       Calendar calendar = Calendar.getInstance();
       calendar.setTime(d);
       calendar.add(Calendar.DAY_OF_MONTH, -7);
       Date sevenDaysEarlier = calendar.getTime();
    		
       return getHibernateTemplate().find("from test.Account account where account.createTime < ?", sevenDaysEarlier);
    }
    Hope this helps!

    -Arthur Loder

    Comment


    • #3
      hi Arthur Loder,

      i see.
      i change my HQL so.
      thank you!

      regards,
      aquaruis

      Comment

      Working...
      X