aspose file tools*
The moose likes Object Relational Mapping and the fly likes Saving system date Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Saving system date " Watch "Saving system date " New topic
Author

Saving system date

deepa karra
Ranch Hand

Joined: Apr 04, 2008
Posts: 46
Hi,
I want to save a record along with current date and time using hibernateDAO.
I am using oracle database. What is the datatype I need to use and also do i need to convert the java date into the oracle date format?
Charan kumar sarvepalli
Ranch Hand

Joined: Dec 14, 2008
Posts: 40
Configure in hbm file <property> type as java.sql.Timestamp and in POJO declare as java.util.Date hibernate will do the remaining.


-- Charan
deepa karra
Ranch Hand

Joined: Apr 04, 2008
Posts: 46
Thanks Charan,
I tried using the <property> as java.sql.timestamp. It is saving the current date. But the time is always being saved as 12:00:00 AM 000

The date is saved as 08/04/10 12:00:00 AM 000.
Aneesh Vijendran
Ranch Hand

Joined: Jun 29, 2008
Posts: 125
The date is saved as 08/04/10 12:00:00 AM 000.


Make sure the object passed to hibernate is also an instance of java.sql.Timestamp

Cheers
Aneesh


Cheers
Aneesh
deepa karra
Ranch Hand

Joined: Apr 04, 2008
Posts: 46
Aneesh,
Thank you. The time is still the same as 12:00:00AM
Aneesh Vijendran
Ranch Hand

Joined: Jun 29, 2008
Posts: 125
Well interesting!

1. How are you constructing the date object (before passing to Hibernate) ?
2. Can you please print the date before passing to hibernate and see if the time is 12:00 am there as well?

If (2) is true, then you know the answer.

deepa karra
Ranch Hand

Joined: Apr 04, 2008
Posts: 46
Hi Annesh,
Thankyou. I solved the problem.
I was parsing the date to MM/dd/yyyy HH:mm:ss using simpledateformat.
Now I changed it as
SimpleDateFormat sdf = new SimpleDateFormat();
Aneesh Vijendran
Ranch Hand

Joined: Jun 29, 2008
Posts: 125
Glad to know that. Happy Hacking!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Saving system date