Search code examples
javaspringjpaeclipselink

Spring JPA, Eclipselink and Auditing


I have been configuring Spring auditing for my entity classes. Using annotations, I have something like this:

@CreatedDate
@NotNull
private Date createdDate

@CreatedBy
@NotNull
private User createdBy

The createdBy field is being set correctly, however persisting the object fails with a null createdDate. I am guessing that this may be related to type conversion for Eclipselink?


Solution

  • @Temporal annotation is available since the release of JPA 1.0. @Temporal solves the one of the major issue of converting the date and time values from Java object to compatible database type and retrieving back to the application.

    @Column(name = "XDATE") @Temporal(TemporalType.DATETIME) private Date xDate; //java.util.Date

    I hope this will resolve your problem. For more info please refer this link