You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Adam Hardy <ad...@cyberspaceroad.com> on 2009/03/09 14:25:49 UTC

Time handling in Dates

I have what looks like a bug in time handling, that probably stems from the 
database Dictionaries. My testing shows it occurs with MySQL and Derby, but not 
for PostgreSQL, H2 or Hypersonic (using latest GA versions of Java, OpenJPA & 
JDBC drivers).

If I save an entity with this set-up, I see incorrect handling of dates:

class MyEntity
{
     ...
     private java.util.Date opening;
     ...
}

and:

<entity>
     <attributes>
       <basic name="opening">
         <column name="OPENING"/>
         <temporal>TIME</temporal>
       </basic>
       ...

and:

create table MY_ENTITY (
     ...
     OPENING time not null,
     ...

In my test I assign a new value to 'opening', save the entity and retrieve it 
from the database again. Then I compare the date on the retrieved entity against 
the value originally assigned, and I get this result:

with Derby: original Calendar.HOUR_OF_DAY == 9, retrieved value = 10

(probably due to Daylight Saving Time handling)

with MySQL: original Calendar.YEAR == 1970, retrieved value = 1969

(could be declared irrelevant since the value comes from a Time database type 
and the Java comparisons should blank out or ignore non-time Date values).

I couldn't find this in JIRA but thought I'd bring it up here before logging it. 
I can post a unit test showing the bug. Shall I do that now?

Regards
Adam

Re: Time handling in Dates

Posted by Adam Hardy <ad...@cyberspaceroad.com>.
logged in Jira:

https://issues.apache.org/jira/browse/OPENJPA-971

Adam Hardy on 09/03/09 13:25, wrote:
> I have what looks like a bug in time handling, that probably stems from 
> the database Dictionaries. My testing shows it occurs with MySQL and 
> Derby, but not for PostgreSQL, H2 or Hypersonic (using latest GA 
> versions of Java, OpenJPA & JDBC drivers).
> 
> If I save an entity with this set-up, I see incorrect handling of dates:
> 
> class MyEntity
> {
>     ...
>     private java.util.Date opening;
>     ...
> }
> 
> and:
> 
> <entity>
>     <attributes>
>       <basic name="opening">
>         <column name="OPENING"/>
>         <temporal>TIME</temporal>
>       </basic>
>       ...
> 
> and:
> 
> create table MY_ENTITY (
>     ...
>     OPENING time not null,
>     ...
> 
> In my test I assign a new value to 'opening', save the entity and 
> retrieve it from the database again. Then I compare the date on the 
> retrieved entity against the value originally assigned, and I get this 
> result:
> 
> with Derby: original Calendar.HOUR_OF_DAY == 9, retrieved value = 10
> 
> (probably due to Daylight Saving Time handling)
> 
> with MySQL: original Calendar.YEAR == 1970, retrieved value = 1969
> 
> (could be declared irrelevant since the value comes from a Time database 
> type and the Java comparisons should blank out or ignore non-time Date 
> values).
> 
> I couldn't find this in JIRA but thought I'd bring it up here before 
> logging it. I can post a unit test showing the bug. Shall I do that now?
> 
> Regards
> Adam
>