-->
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.  [ 1 post ] 
Author Message
 Post subject: Timezone used when fetching a Datetime column...
PostPosted: Mon Oct 15, 2007 1:47 pm 
Newbie

Joined: Fri Oct 12, 2007 3:25 pm
Posts: 1
Location: Sausalito
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.2.4.sp1

Jboss version: 4.2.1-GA

Sample code of my bean:
@Entity
@Table(name = "sample_value")

public class DbSampleValue extends Value<DbSampleValueId> {
private Date datetimeA;
...
@Column(name = "datetime_a")
public Date getDatetimeA() {
return datetimeA;
}

protected void setDatetimeA(Date datetimeA) {
this.datetimeA = datetimeA;
}

Name and version of the database you are using:MySQL, version: 5.0.45-community-nt

Debug level Hibernate log excerpt:
17:07:38,062 INFO [Version] Hibernate EntityManager 3.2.1.GA
17:07:38,093 INFO [Version] Hibernate Annotations 3.2.1.GA
17:07:38,343 INFO [Environment] Hibernate 3.2.4.sp1


So my issue is a Datetime column stored in mysql is getting adjusted to the timezone of my system (JVM) when that column is being fetched and my bean is called (with the @Column annotation). Here are the specifics:

Timezone is set to PST on my window XP machine where jboss is running.
Value (long) stored in mysql: 2007-07-13T23:33:00Z or 1184369580000 ms.
Value (long) returned in my setDatetime method: 1184394780000 ms.

Therefore, the only way for me to be sure that the long value returned by this fetch is the same as what went in is to either set the Timezone of my machine to GMT or pass in the property of user.timezone=GMT when I start up Jboss.

Is there a way that I can set the timezone programatically for Hibernate? I've tried static initializers on some of my Hibernate related classes where I set the java timezone property, however they have no effect.

I have see the post for creating your own custom type: http://www.hibernate.org/100.html however I was hoping that there would be something more simple than this. I was hoping that if I could get at the right classloader I could set this property for Hibernate but perhaps I'm missing something.

Any help would be greatly appreciated.

Thanks!

_________________
Carlo Latasa - Motionbased a division of Garmin


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

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.