0

How do I save timestamps in mysql DB using a hibernate entity in specific format.

Hibernate Entity Class:

@CreationTimestamp
@Column(name="created_on", nullable = false, updatable = false)
private LocalDateTime createdOn;

@UpdateTimestamp
@Column(name="updated_on", nullable = false)
private LocalDateTime updatedOn; // = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

I have also used DateTimeFormatter and SimpleDateFormat but they all gave the same error:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.HibernateException: Unsupported property type [java.time.format.DateTimeFormatter] for @CreationTimestamp or @UpdateTimestamp generator annotation

application.properties:

spring.jpa.hibernate.ddl-auto=update
Deepak Bisht
  • 45
  • 1
  • 5

1 Answers1

0

The error suggests that one of the non-static fields is of type DateTimeFormatter and is annotated with @CreationTimestamp or @UpdateTimestamp which is illegal. These annotation can only be applied to fields of type java.util.Date, java.util.Calendar, java.time.LocalDateTime etc.

Christian Beikov
  • 15,141
  • 2
  • 32
  • 58