-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: Date increased by one hour on retrieval
PostPosted: Tue Sep 27, 2005 4:10 pm 
Beginner
Beginner

Joined: Wed Sep 21, 2005 11:52 am
Posts: 43
I have a domain object that uses a component to hold various date related information. The component uses GregorianCalendar to hold actual date information. This all works fine as far as saving and retrieving the domain object and the component. However, after retrieval one of the GregorianCalendar objects in the component (mySimpleDate, the only one that actually has a value in this case) is one hour (exactly) ahead of what its original value was (and what is stored in the database).

Hibernate version:
3.0.2

Mapping documents:
<class name="org.egcrc.cfr.normalized.NormalizedRecord"
table="NORM_REC"
lazy="true">
...
<component name="myEventDate" class="org.egcrc.cfr.common.Date">
<property name="myIsSimpleDateApproximate" column="EVENT_DATE_IS_APPROX" type="boolean"/>
<property name="myMaxDate" column="EVENT_MAX_DATE" type="java.util.GregorianCalendar" />
<property name="myMinDate" column="EVENT_MIN_DATE" type="java.util.GregorianCalendar"/>
<property name="mySimpleDate" column="EVENT_DATE" type="java.util.GregorianCalendar"/>
</component>
...
</class>

Code between sessionFactory.openSession() and session.close():
...
NormalizedRecord normRec1 = bisRecord.normalize();
Transaction tx = session.beginTransaction();
session.save(normRec1);
tx.commit();
...
Transaction tx = session.beginTransaction();
NormalizedRecord normRec2 = (NormalizedRecord)session.get(NormalizedRecord.class, id);
tx.commit();

Full stack trace of any exception that occurs:

Name and version of the database you are using:
DB2

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:
This message occurs as the session.get() us executed. The date is correct here:

DEBUG org.hibernate.pretty.Printer - org.egcrc.cfr.normalized.NormalizedRecord{myEventDate=component[myIsSimpleDateApproximate,myMaxDate,myMinDate,mySimpleDate]{myMinDate=null, mySimpleDate=1935-11-30 23:00:00, myMaxDate=null, myIsSimpleDateApproximate=false}, mySourceId=, myRoles=<uninitialized>, myRecordType=BIRTH_INDEX_RECORD, myCreateDate=2005-09-27 12:45:10, myId=6}

This sounds like a daylight savings time or timezone issue, but I have checked those on the DB2 server and the workstation I run the application on and there is no difference.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 27, 2005 5:15 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
you should always compare the actual milliseconds value to validate the contents of dates - not their printed value.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 27, 2005 5:25 pm 
Beginner
Beginner

Joined: Wed Sep 21, 2005 11:52 am
Posts: 43
I was a bit incorrect in my original post. Here are the various representations of my date-time value:

1. The original string: "12/1/1935"

2. I parse this and create an instance of GregoriqanCalendar whcih has these values:
year=1935, month=11, day=1, hour=0, minute=0, second=0

NOTE: The month is 0-based so this is correct.

3. I save the object containing this date into the database. In the database the field value looks like this:

1935-11-30 23:00:00

This is one hour less than it should be. This must be either a DB2 problem or a Hibernate problem.

4. Now i retrieve the object containing the date. As expected it creates a GregorianCalendar with the wrong value:
year=1935, month=10, day=30, hour=23, minute=0, second=0

Hibernate correctly instantiated the GregorianCalendar from the data, so the finger seems to be pointing at DB2.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 27, 2005 5:30 pm 
Beginner
Beginner

Joined: Wed Sep 21, 2005 11:52 am
Posts: 43
max wrote:
you should always compare the actual milliseconds value to validate the contents of dates - not their printed value.


I'm actually comparing the dates using equals().

assertEquals(normRec1, normRec2);

The equals method traverses through the objects and eventually compares the date components I described in my original post. Exactly what GregorianCalendar.equals() does I don't know but it does not just check for identity. In any case the two dates have values that differ by an hour. The millisecond values are not the same.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 14, 2005 4:47 pm 
Newbie

Joined: Fri May 06, 2005 6:04 pm
Posts: 11
Location: ES - Brazil
Hi,

this is may be a problem of JAVA day light saving.

If you try
Code:
System.out.println( TimeZone.getDefault().inDaylightTime(gregorianCalendar.getTime()));


it will probably print "true".


let me know if this is the problem...
Pedro


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 14, 2005 5:37 pm 
Beginner
Beginner

Joined: Wed Sep 21, 2005 11:52 am
Posts: 43
I solved this problem by replacing the DB2 driver.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.