-->
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: HIbernate Date Formats
PostPosted: Tue Mar 15, 2011 1:02 pm 
Newbie

Joined: Thu Aug 20, 2009 7:20 am
Posts: 5
Hi,

Just a bit of background so I don't get bombarded with questions about WHY I want to do what I am doing.

We have a Flex application communicating to a Java (GraniteDS) back end. Flex/AMF3 serializes Dates as just a number that represents UTC milliseconds from the epoch with NO time zone component so both Flex and Java assume local time zone for all Dates. In cases where you are only interested in the date, this causes problems; Flex and Java attempt to adjust based on their respective time zones, frequently resulting in the date being inadvertently changed. For example, if you send 3/1/2011 with no time component (defaults to 00:00:00) from a Flex client in the UK back to a Java server in EST, it subtracts hours and ends up storing the data as 2/28/2011 instead. As a workaround, we need to send the dates over the wire as strings, to bypass Flex's insistence on performing these unwanted Date adjustments.

So ... my question ...

I have a String instance variable on my entity class and I want to map it to a DATE column in Oracle. The problem is that when I do queries, Hibernate selects the format 'YYYY-MM-DD HH:MI:SS' to return the string, but if I try to save the same object back, it simply tries to insert a string in that format, which of course fails because the Oracle default is 'DD-MON-YY'.

Is there any way short of defining my own custom type to force Hibernate to use the same 'DD-MON-YY' format when it selects the DATE column into a String? It seems to me that the mapping should at least be symmetrical ... i.e. if you query the object in Hibernate without error, you should be able to update/insert the same object ... but that is not what I am observing.


Top
 Profile  
 
 Post subject: Re: HIbernate Date Formats
PostPosted: Tue Mar 15, 2011 4:55 pm 
Newbie

Joined: Thu Aug 20, 2009 7:20 am
Posts: 5
FYI, I ended up implementing a custom type to solve the problem. It turned out to be a little easier than I originally thought so I finished it before anyone had a chance to reply to this post. Still if there is an easier way, I would be curious to know what that is. Thanks.


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.