Meaningless Drivel is fun!*
The moose likes Object Relational Mapping and the fly likes Hibernate date in criteria Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate date in criteria" Watch "Hibernate date in criteria" New topic
Author

Hibernate date in criteria

Sunny Leung
Greenhorn

Joined: Jun 29, 2010
Posts: 5
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 agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate date in criteria
 
Similar Threads
Hibernate & Date
Regular Expression help
Communique & WebSphere 5.0
Restrictions Between for Date in Hibernate Criteria
How to identify Auth method NTLMv1 or NTLMv2