-->
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.  [ 5 posts ] 
Author Message
 Post subject: Problem taking into account Timezones when writing date
PostPosted: Tue Jun 14, 2005 10:13 am 
Beginner
Beginner

Joined: Thu Apr 21, 2005 12:15 pm
Posts: 34
Hi I have a server running in a particular timezone. I am wring a date to an oracle database using Hibernate and I want it to write the GMT Date.
into Oracle

My Code is as follows:
Code:
final Transaction t = s.beginTransaction();                     
TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
date d = Calendar.getInstance().getTime();
System.out.println(d);
Widget.setDate(d);
Widget.save();
t.commit();


Outputting the date field shows is as GMT e.g
14 Jun 2005 13:04:48 GMT

but when written to Oracle and SQL Statements shows it has been set to June 15 (my client is set to show dates as GMT)

The entry in my Hibernate Mapping is defined as thus
Code:
  <property name="createddt" type="java.util.Date" insert="true" optimistic-lock="true" not-null="false" update="true" unique="false" lazy="false">
      <column name="CREATED_DT" length="7" not-null="false" sql-type="DATE"/>
    </property>


Hibernate seems to be ignoring my Timezone setting and writing it using the default Timezone of my machine (which is 13 hours ahead).


How can I get round this ?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 14, 2005 10:27 am 
Regular
Regular

Joined: Mon Jul 26, 2004 2:28 pm
Posts: 86
Location: Pensacola, Florida
Declare the SQL type as TIMESTAMP(3) WITH TIMEZONE.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 14, 2005 11:06 am 
Beginner
Beginner

Joined: Thu Apr 21, 2005 12:15 pm
Posts: 34
I did changed just the SQL type in the Hibernate file, but this didnt make any difference.

Do you mean change the actual DDL of the table. I dont have the opportunity to chnage this I want Hibernate to work with the existing Schema


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 16, 2005 10:21 am 
Regular
Regular

Joined: Mon Jul 26, 2004 2:28 pm
Posts: 86
Location: Pensacola, Florida
I meant change the DDL, but since that is not an option, try the using "Calendar" or "calendar_date" as the type in your Hibernate mapping file. The DateType uses the PreparedStatement.setDate(int, java.sql.Date) signature, while the CalendarDateType uses the PreparedStatement.setDate(int, java.sql.Date, java.util.Calendar) signature, which may or may not do what you want. The JDBC API isn't super clear on the exact behavior of the PreparedStatement.setDate(int, java.sql.Date, java.util.Calendar) (it just says "The driver uses the Calendar object to construct an SQL DATE value"), but I think it is supposed to do what you are looking for.

- Jesse


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 21, 2005 6:02 am 
Beginner
Beginner

Joined: Thu Apr 21, 2005 12:15 pm
Posts: 34
I changed type to Calendar but it made no difference


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