• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate Date auto Generation

 
Abiodun Adisa
Ranch Hand
Posts: 495
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a column in my database that stores the date the Data was inserted into a table, Is there a way for Hibernate to auto generate the date whenever i attempt to insert data into the database
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, in your mapping you can set a default, you can set a formula, anything such that when it saves your users don't have to enter the data, but Hibernate will do it for you. You can even put database specific codewords in that formula and Hibernate will pass it directly through to the database. It also can call an insert trigger. Also in most databases you can set a default value, so for a date in Oracle you can have a default value of date() and when you first insert a record it will put today's date into the record.

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic