-->
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: storing timestamp
PostPosted: Wed Mar 05, 2008 6:16 am 
Newbie

Joined: Wed Mar 05, 2008 6:03 am
Posts: 3
I have a column in a table with datatype Date.
And in the mapping file, i mentioned the type="timestamp"

The associated POJO for my table generates the column with Date.

Its setter() is accepting only Date as a parameter.

But when i persist, i am able to save only Date and i am unable to save the time along with date.

can anybody suggest me on this how to proceed.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 05, 2008 11:55 am 
Senior
Senior

Joined: Fri Jun 01, 2007 12:41 pm
Posts: 121
Change the column type to java.sql.Timestamp and keep the hibernate mapping as 'timestamp'. It will return date+time.

I have mapped the following two columns with Date and TimeStamp type to hibernate type 'timestamp'

private Date myDate; (java.util.Date)
private TimeStamp yourDate; (java.sql.Timestamp)

My database is Oracle. In my tables, I can see that both date and time are stored. When query for myDate and yourDate, only Date is returned.

myDate returns date only.
yourDate returns date+time.

But when you issue a SQL in database with to_char(myDate, 'yyyy-mm-dd hh:mm:ss') it returns date+time. But the java type java.util.Date is returning date only.

Here is what Hibernate docs says:

Quote:
Mapping type-->Java type---->Standard SQL built-in type
date-->java.util.Date or java.sql.Date DATE-->
time-->java.util.Date or java.sql.Time-->TIME
timestamp-->java.util.Date or java.sql.Timestamp-->TIMESTAMP
calendar-->java.util.Calendar-->TIMESTAMP
calendar_date-->java.util.Calendar-->DATE


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.