This week's book giveaway is in the Open Source Projects forum.
We're giving away four copies of Spark in Action and have Jean-Georges Perrin on-line!
See this thread for details.
Win a copy of Spark in Action this week in the Open Source Projects forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

How to solve the date issue in hibernate query?

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,
Posts: 17346
Mac IntelliJ IDE 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

And in the documentation the built-in types

I also highly recommend using bind parameters if you are going to use Dates in your where portion of your query.

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.

Men call me Jim. Women look past me to this tiny ad:
Thread Boost feature
    Bookmark Topic Watch Topic
  • New Topic