-->
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.  [ 2 posts ] 
Author Message
 Post subject: Wrong time inserted in database
PostPosted: Wed Oct 15, 2008 7:20 pm 
Newbie

Joined: Wed Oct 15, 2008 6:47 pm
Posts: 7
Location: Vancouver
I have a Java Date field:
Code:
private Date startDate;


Its Hibernate mapping:
Code:
<property name="startDate"/>


Generated SQL (PostGreSQL):
Code:
column start_date timestamp;


When I execute this (setting the date field from a String):
Code:
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
Date date = dateFormat.parse("2008-10-15 10:11");
// date = Wed Oct 15 10:11:00 GMT-08:00 2008
robot.setStartDate(date);


In the database the time is wrong: 11:11 instead of 10:11. The hour gets the minutes value!

What would be the explanation?
I'm using Java 1.5, Hibernate 3 and PostGreSQL 8.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 16, 2008 1:19 pm 
Newbie

Joined: Wed Oct 15, 2008 6:47 pm
Posts: 7
Location: Vancouver
Sorry, that wasn't an HIbernate problem. Just when doing
Code:
new Date()

this date was off by one hour compared to the computer date.

It was an Java on Ubuntu issue relative to daylight saving time:
https://bugs.launchpad.net/ubuntu/+sour ... omments/13

This solved it:
Code:
sudo cp /etc/localtime /etc/localtime.bak
sudo ln -s -f /usr/share/zoneinfo/Canada/Pacific /etc/localtime


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.