• 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

writing a HQL query with date calculation

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The mySQL query below is what I want to write in HQL to obtain a list of all objects with the respective id's.
The fields in the query;
last_update_date is a date &
interval is an integer specifying the number of days.

select acct_id from profiles where sysdate() >= adddate(last_update_date, interval)

Thanks in advance for any help in figuring this out.
 
Vijay Chauhan
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I figured it out!
Didnt know i could just use mySQL functions directly in the HQL statement.
Here is the solution for anyone who might be interested;
List result = session.createQuery("from Profile as profile where sysdate() >= adddate(profile.lastUpdateDate, profile.interval ) )").list();

Originally posted by Vijay Chauhan:
The mySQL query below is what I want to write in HQL to obtain a list of all objects with the respective id's.
The fields in the query;
last_update_date is a date &
interval is an integer specifying the number of days.

select acct_id from profiles where sysdate() >= adddate(last_update_date, interval)

Thanks in advance for any help in figuring this out.


[ December 06, 2006: Message edited by: Vijay Chauhan ]
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, the cool thing about HQL, is that if Hibernate doesn't understand a particular syntax, say a call to sysdate() or your adddate function that is in SQL, then it just passes the text to the database. Meaning if the database suports those functions it will work. So it means that your HQL query doesn't have to always have just HQL, but some SQL can work, but remember when referring to Objects and Attributes you need those object.attribute referencing.

Mark
 
Vijay Chauhan
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for that explanation Mark! And yes that is really cool about hibernate that instead of breaking, it just attempts to send it to the DB as text.
 
reply
    Bookmark Topic Watch Topic
  • New Topic