• 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

How to get ' current timestamp' from DB2 database in hibernate using HQL or Criteria

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was just wondering how to get the 'current timestamp or date' from DB2 database using hibernate query language(hql) or some other way in hibernate.

you can say something similar to this , but using hql or criteria or some other way in hibernate.

SELECT current timestamp FROM sysibm.sysdummy1

It is so surprising that i could not find some simple way of doing this in hibernate.

I will appreciate any help regarding that.
 
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
You have to do it with with SQL (see session.createSQLQuery() ). I'd suggest caution though. Using the DB server time is not going to be as portable as getting the time in the Java app and persisting that. Its usually the application's time which is important too, not the DB server's time. Which is why I think the Hibernate people have not thought it important to include in HQL.
 
Munish Dabra
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Paul..But sometimes one has no choice since database server and application server may be in different timezone.and making your application dependent on timezone esp when you are using timestamp to compare with one of the other columns in database is risky..Is n't it?

I tried using createSQLQuery() too...but i am getting alias exception...I will appreciate if you can tell me which persistant objec to use while writing query.
 
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

Originally posted by Munish Dabra:
Thanks Paul..But sometimes one has no choice since database server and application server may be in different timezone.and making your application dependent on timezone esp when you are using timestamp to compare with one of the other columns in database is risky..Is n't it?

I tried using createSQLQuery() too...but i am getting alias exception...I will appreciate if you can tell me which persistant objec to use while writing query.



I suppose you could - but it would be a fairly odd set up wouldn't it? Assuming your database(s) and app server(s) are in the same physical location, why would they be configured to use different timezones?
 
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you can use something like :
select current_timestamp() from Product pb where pb.pId='1'

The functions viz. CURRENT_DATE(), CURRENT_TIME(), CURRENT_TIMESTAMP() are native HQL functions.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic