Hi All,

I am developing an app using AppFuse 2.0 with Hibernate and Struts 2.  
I've just finished refactoring it to use Joda-time components and I 
really like their clean functionality, thanks for all the effort that's 
gone in so far.

I'm having a problem with searching date fields in the database 
however.  It's hard to know if it's a Joda-time issue or a Hibernate 
issue, but hopefully folks here can help me work that out.

The application I'm developing will only ever be run within the one 
timezone - here in Western Australia (UMT + 9 with summertime).  One of 
the reasons I introduced Joda-time was to help eliminate some unwanted 
timezone issues I was getting with java.util.Date.

So, I elected to use joda LocalDate, LocalTime and LocalDateTime types 
throughout my application, believing that would eliminate my TZ-related 
problems.  It seems to have done that, with one exception.

When I query the Database via Hibernate, there seems to be some sort of 
date adjustment happening that I am assuming is TZ related.

I am building my query using Hibernate's Criteria class.  I set my date 
criteria as follows:

criteria.add(Expression.between("departureDate", startDate, endDate);

where "departureDate" refers to a POJO attribute that has been defined 
using the appropriate @Type annotation as a PersistentLocalDate and 
"startDate" and "endDate" are LocalDate variables.

My problem is that when I execute this query, the dates are being 
"shifted left" by one day.  For example, if I'm searching for dates 
between today (12 Dec here) and 7 days hence (19 Dec), I find that the 
query Hibernate executes has the parameter values '11 December 2007' and 
'18 December 2007' respectively.  I've traced the code and confirmed 
that at the point of adding the criteria (via the code snipped above) 
the 'startDate' and 'endDate' values are correct (looking at them via 
the Eclipse debugger).

Can anyone explain to me why this is happening and how I can stop it 
from happening?

In case it's relevant, my development db is Postgres and the relevant 
column has been defined as type "date" (created programmatically by 
Maven using Hibernate's hbm2ddl goal).  FWIW, my Test and Prod DBs are 
Oracle, but I've not got to the point of deploying to the Test platform yet.

TIA,
Rob Hills
Waikiki, Western Australia


-------------------------------------------------------------------------
SF.Net email is sponsored by: 
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Joda-interest mailing list
Joda-interest@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/joda-interest

Reply via email to