• 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 solve the date issue in hibernate query?

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Frnds,

In my code the query is generated like this...

select * from TableA where currDate = 'Fri Jun 01 14:47:45 IST 2007'

I'm using java.util.Date in my code.But the database(MySQL) has different Date format like '2007-06-01 14:47:45'.

So obviously my query doesn't return the correct result. Can you suggest How to solve this problem?

Thanks in Advance,
Senthil.
 
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
Each database has a different format for Date, and that is what a dialect covers and what you put in for your mapping of that column, but I suggest looking at the hibernate documentation pages like in the faq here

http://www.hibernate.org/116.html#A37

And in the documentation the built-in types
http://www.hibernate.org/hib_docs/v3/reference/en/html_single/#mapping-types-basictypes

I also highly recommend using bind parameters if you are going to use Dates in your where portion of your query.
http://www.hibernate.org/hib_docs/v3/reference/en/html_single/#objectstate-querying-executing-parameters

SO what you didn't mention is how your query is created, is it a Criteria, Query or SQLQuery object your create from your session. And how do you build your query.

Mark
reply
    Bookmark Topic Watch Topic
  • New Topic