• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

Saving system date

 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Aneesh,
Thank you. The time is still the same as 12:00:00AM
 
Aneesh Vijendran
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Glad to know that. Happy Hacking!!
 
Trust God, but always tether your camel... to this tiny ad.
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic