-->
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.  [ 3 posts ] 
Author Message
 Post subject: Hibernate and Oracle Timestamps
PostPosted: Thu Oct 11, 2007 12:55 am 
Regular
Regular

Joined: Tue Oct 10, 2006 2:21 pm
Posts: 58
Hibernate version: 3.05

Ouch, such a headache! When I initially set out my Hibernate mappings, I decided to map Date-Time type data as Calendar on the java side and their Timestamp counterpart on the database side (Oracle). I thought I was sitting pretty, but now I'm not so sure. My thinking was that a Calendar was at bottom a number of milliseconds past midnight 1/1/70 UTC, and that I could always convert to another timezone with this backing, which is not the case with Date.

The problem comes in because of the following strange requirement: the app server that runs Hibernate to WRITE the timestamps to the database is currently in one TimeZone (US Central) and the app server that runs Hibernate to READ the timestamps is in a different TimeZone (US Eastern). And this is just a temporary configuration. My app cannot assume it will always be thus. And must we also consider the timezone of the Database server? When this is finally displayed to the End user, using HIS timezone, whatever that may be, we are getting off by one hour errors. I am not sure what the cause yet is but I think I know.

I don't currently normalize the time data. I had thought (see above) that the long value of the calendar would be preserved across database reads. But it doesn't seem so. A timestamp I read in the database as 11:35 AM, upon being read assumes it's 11:35 EDT according to my logs, whereas the logs as it was being written said it should have been 11:35 CDT. Where did my hour get eaten?

I could, I suppose normalize the Calendar to UTC before writing it to the database, but what TimeZone does Hibernate use in the Calendar it creates when reading from the database. If it's the default timezone of the machine doing the reads, I'm screwed. I don't particularly want to do a lot of parsing/formatting just to keep things sane. I'd like to use the Oracle datatype Timestamp with Time Zone but I'm not finding much Hibernate support doing so. Basically I want a system that stores a normalized timestamp without too much effort. I thought Calendar did that for me, it now looks not to be the case.

Does anyone have any answers to this dilemma? I now think I might have been better off manually normalizing to UTC, storing as DATEs and then assuming UTC at the other end and owning all my adjustments. But it's too late for that now. I need to live with the same DB structure and minimal if any code changes.


Top
 Profile  
 
 Post subject: Found this article on your site
PostPosted: Thu Oct 11, 2007 7:24 am 
Regular
Regular

Joined: Tue Oct 10, 2006 2:21 pm
Posts: 58
http://www.hibernate.org/100.html

It seems to describe my situation. There is some question of whether the information here is relevant to Hibernate 3.x, particularlym 3.05. Is it still relevant?


Top
 Profile  
 
 Post subject: Ok, I really do need a little help from the team on this one
PostPosted: Thu Oct 11, 2007 10:37 am 
Regular
Regular

Joined: Tue Oct 10, 2006 2:21 pm
Posts: 58
Can someone on the Hibernate team please answer as to the relevance of the approach on http://www.hibernate.org/100.html to Hibernate 3.x. ?

For one thing, it doesn't compile. Aside from the package migration, it seems that the UserType interface gained a few new methods that need to be implemented. While these look fairly trivial, I am under extreme time pressure now and can't play around with this. I'm just looking for some guidance as to whether there's a standard Hibernate 3 way of handling this or if I should just start from the approach on the Web page as a model and build something that works.


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