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!