• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to solve the date issue in hibernate query?

 
Senthilrajan Chennai
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • 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.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic