-->
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.  [ 4 posts ] 
Author Message
 Post subject: Date dd-Mon-yy is not returned correctly by Hibernate
PostPosted: Tue Aug 24, 2010 5:29 am 
Newbie

Joined: Thu Dec 17, 2009 11:43 am
Posts: 6
I am having an Oracle database which is storing date as 'dd-Mon-yy', example date is 14-JAN-97 03.25.03 PM.

When I am getting this data from Hibernate I get date as- '14 January 2097'. How do I correct this?

Here is debug output: DEBUG - returning '14 January 2097' as column: CREATION8_10_0_

However if I execute the SELECT query against database then I get correct date: 14-JAN-97 03.25.03 PM.

Here is how my field is defined in Oracle-
Code:
"CREATION_DATE" DATE


And here is how it is mapped [mapping generated from Hibernate Tools],
Code:
<property name="creationDate" type="date">
     <column name="CREATION_DATE" length="7" />
</property>


Top
 Profile  
 
 Post subject: Re: Date dd-Mon-yy is not returned correctly by Hibernate
PostPosted: Tue Aug 24, 2010 5:41 am 
Newbie

Joined: Thu Dec 17, 2009 11:43 am
Posts: 6
I changed the type to 'timestamp' in mapping file, but it is still returning wrong date,

DEBUG - returning '2097-01-14 15:25:03' as column: CREATION8_10_0_


Top
 Profile  
 
 Post subject: Re: Date dd-Mon-yy is not returned correctly by Hibernate
PostPosted: Tue Aug 24, 2010 2:40 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Hello,
date(s) are not stored like that but as numbers, usually like "long", what you see is just a representation, Hibernate is not converting it to a string but it's converted at some point after that, implicitly by a call to toString() by the logger/sysout/debugger (wathever you used to see those strings) or explicitly by some conversion that you have applied after receiving the Date instance from Hibernate.
Also make sure that the database and your server are using the same timezone, or they won't ever match ;-)

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: Date dd-Mon-yy is not returned correctly by Hibernate
PostPosted: Wed Aug 25, 2010 12:57 pm 
Beginner
Beginner

Joined: Thu Dec 11, 2008 8:18 am
Posts: 35
Change the creationDate type to String and add formula in property tag.

<property name="creationDate" type="string" formula="to_char(creationDate,'DD-MON-YY')">
<column name="CREATION_DATE" />
</property>

This will work.


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