Help coderanch get a
new server
by contributing to the fundraiser
  • 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 ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

Hibernate date in criteria

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

I've developed an application that simply pulls records from the DB out, and allows the user to select the date/time range to choose from (along with a bunch of other criteria). This has worked really well up till recently when the DB server (SQL Server 2005) was physically changed to one in another location.

Below is the criteria I'm using:

(I'm not using 'between' as either end of the limit is optional)

I've also been able to run SQL queries like this:
(for March 4th)

When we moved to the new DB server I found the application stopped returning correct results.

I'm no expert here, but I'm guessing the locale of the new server is different, and I've needed to specify the month and day switched around
(for March 4th)
I've confirmed that this is returning March 4th by doing a CONVERT on created_datetime on the returned results.

I would've thought that Hibernate would've been able to abstract me from this change. However, I confirmed that by turning on show_sql that:

This would mean "2011-03-04 xx:xx:xx" is being used in the SQL to the new DB server, which means April 3rd to the DB server instead of March 4th (imagine the irony - we changed the server yesterday, March 3rd, so this didn't show up!!)

Is there a way for Hibernate to use a 'standard' format? I can confirm that if I was able to send something like "2011-03-04T23:59:59" then both servers will interpret this as March 4th.

Have I misunderstood/misused something?
I am not young enough to know everything. - Oscar Wilde This tiny ad thinks it knows more than Oscar:
We need your help - Coderanch server fundraiser
    Bookmark Topic Watch Topic
  • New Topic