1

I would like to define in my Entity a insert_time field that automatically is generated by Hibernate when persisting it.

I am using java.util.LocalDateTime with @CreationTimestamp but it is still null in DB. I am using H2. In addition, I would like to use joda instead.

lordneru
  • 700
  • 7
  • 19
  • 1
    Hibernate 5.4 supports LocalDateTime: https://docs.jboss.org/hibernate/orm/5.4/javadocs/org/hibernate/annotations/CreationTimestamp.html; Hibernate 4 does not: https://docs.jboss.org/hibernate/orm/4.3/javadocs/org/hibernate/annotations/CreationTimestamp.html. What version are you using? If you're using Java 8+, the Joda maintainers recommend sticking to the JDK classes (https://stackoverflow.com/questions/29750221/is-joda-time-deprecated-with-java-8-date-and-time-api-java-time) – Not a JD Mar 27 '19 at 15:44
  • I am using spring boot starter data 2.1.3-RELEASE. According to the Maven reppository, it is using 5.3.7 and there is an update 5.4.2-final. – lordneru Mar 27 '19 at 17:10
  • I have imported the 5.4.2 version of hibernate core and I still see NULL in database for date_time annotated with `@CreationTimestamp` of java.time. – lordneru Mar 27 '19 at 18:52
  • what's the field type of date_time that's annotated with @CreationTimestamp? – Not a JD Mar 27 '19 at 19:19
  • java.time.LocalDateTime; – lordneru Mar 27 '19 at 19:54
  • Finally It worked using `@Column(columnDefinition="TIMESTAMP DEFAULT CURRENT_TIMESTAMP")` and removing the `@CreationTimestamp`. – lordneru Mar 27 '19 at 20:10
  • Seems relevant: http://blog.schauderhaft.de/2018/03/14/dont-use-localdatetime/ – Jens Schauder Mar 28 '19 at 10:29

0 Answers0