How can you make a created_at column generate the creation date-time automatically like an ID automatically gets created?

JPA

There isn’t anything as convenient as annotating the Timestamp field directly but you could use the @PrePersist, @PreUpdate annotations and with little effort achieve the same results.

Hibernate

  • @CreationTimestamp – Documentation
  • @UpdateTimestamp – Documentation

Spring Data JPA

  • @CreatedDate – Documentation
  • @LastModifiedDate – Documentation

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)