File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Saving system date

 
deepa karra
Ranch Hand
Posts: 46
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 40
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Configure in hbm file <property> type as java.sql.Timestamp and in POJO declare as java.util.Date hibernate will do the remaining.
 
deepa karra
Ranch Hand
Posts: 46
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 125
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
deepa karra
Ranch Hand
Posts: 46
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aneesh,
Thank you. The time is still the same as 12:00:00AM
 
Aneesh Vijendran
Ranch Hand
Posts: 125
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 46
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 125
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Glad to know that. Happy Hacking!!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic