-->
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: Saving Timestamp or Date as UTC/GMT in oracle
PostPosted: Thu Nov 18, 2010 2:26 pm 
Newbie

Joined: Thu Nov 18, 2010 1:46 pm
Posts: 3
Although I've tried several ways to do this, I thought I'd ask the question first rather than try and fix my attempts...

I am using Oracle db and reveng my hbm.xml and java files. I want to save timestamp information in a column of oracle type TIMESTAMP(6) (see JMS_TMSTP). I have tried to do this, but it keeps converting it to the local timezone. I have a CRTE_DTTM column that is automatically set by the DEFAULT value when the row is created. When i query the database I get:

TIMESTAMP(6) TIMESTAMP(6) DEFAULT SYS_EXTRACT_UTC(SYSTIMESTAMP)
JMS_TMSTP CRTE_DTTM
------------------------- -------------------------
18-NOV-10 09.47.40.033000000 AM 18-NOV-10 04.48.36.707979000 PM

I can see that 'somewhere' it has converted the JMS_TMSTP value from what I set in to in my java app into the local time (Arizona) (currently GMT-7).

So, what's the 'right' way to go about persisting times as UTC in the database using hibernate?


Top
 Profile  
 
 Post subject: Re: Saving Timestamp or Date as UTC/GMT in oracle
PostPosted: Thu Nov 18, 2010 5:37 pm 
Newbie

Joined: Thu Nov 18, 2010 1:46 pm
Posts: 3
I don't know if this is a good fix, but it seemed to work for me...

I simply put the following code in:
TimeZone.setDefault(TimeZone.getTimeZone("GMT"));

This sets the app's default timezone to what I want to work with. I got the idea from http://blog.jadira.co.uk/blog/2010/5/1/javasqldate-types-and-the-offsetting-problem.html about 1/2 way down, it says:

Note that the same result could have been achieved by simply changing the default time zone, and not passing the Calendar explicitly since the JDBC driver will use the default time zone by default.
...from 10.5 Date, Time, and Timestamp, p47, JDBC 2.1 API Version 1.1, Seth White and Mark Hapner. October 5, 1999 4:39 pm

So it looks like the driver was converting it, and setting the default zone fixes the issue. Anyway, now the db looks like this:


JMS_TMSTP TIMESTAMP(6)
-------------------------
18-NOV-10 09.32.26.026000000 PM

CRTE_DTTM TIMESTAMP(6) DEFAULT SYS_EXTRACT_UTC(SYSTIMESTAMP)
-------------------------
18-NOV-10 09.32.32.801257000 PM


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.