Java 8 LocalDate in hibernate wrongly mapped to TIMESTAMP

I suspect that you have the following code somewhere in your project:

@EntityScan(basePackageClasses = { Application.class, Jsr310JpaConverters.class })

If you are using Hibernate 5.x you should remove the reference to Jsr310JpaConverters.class otherwise both Hibernate and Spring will attempt to handle Java 8 Date and Time objects. This can result in some very inconstant behaviour (such as LocalDate instances being persisted with the wrong value when running on machines that do not use UTC).

You should also remove any occurrences of:

@Column(columnDefinition = "DATE")

If you require it, it is a indication that something is seriously wrong with your hibernate configuration.


I've not used this in Spring but in "standard" JPA, I've done something like:

@Converter(autoApply = true)
public class OffsetDateTimeAttributeConverter implements AttributeConverter<OffsetDateTime, Timestamp> {
    @Override
    public Timestamp convertToDatabaseColumn(OffsetDateTime entityValue) {
        if( entityValue == null )
            return null;

        return Timestamp.from(Instant.from(entityValue));
    }

    @Override
    public OffsetDateTime convertToEntityAttribute(Timestamp databaseValue) {
        if( databaseValue == null )
            return null;

        return OffsetDateTime.parse(databaseValue.toInstant().toString());
    }
}

My table has "timestamp with timezone" columns. My @Entity then uses OffsetDateTime. You should be able to convert between your datatypes with something like this.


So I got it to run, by adding a columnDefinition="DATE" to the @Columnannotation.

@Entity
@Table(name = "my_alarms_timeline", indexes = {...})
public class MyAlarm {
    ...
    @Column(name = "validity_date", columnDefinition = "DATE")
    @NotNull
    private LocalDate validityDate;
}

Not sure why nobody else is seeing this issue...