According to this source, JPA 2.1 does not natively support the new Date and Time API introduced with Java 8.
The author’s explanation is as follows:
The Answer is simple, JPA 2.1 was Released before Java 8 and the Date and Time API Simply didn’t exist at that point in time. Therefore the @Temporal Annotation can only be Applied to Attributes of type java.util.Date and java.util.Calendar.
The solution presented by the same source above is to use the Attributeconverter (credits to the author)
import java.sql.Date;
import java.time.LocalDate;
@Converter(autoApply = true)
public class LocalDateAttributeConverter implements AttributeConverter<LocalDate, Date> {
@Override
public Date convertToDatabaseColumn(LocalDate locDate) {
return locDate == null ? null : Date.valueOf(locDate);
}
@Override
public LocalDate convertToEntityAttribute(Date sqlDate) {
return sqlDate == null ? null : sqlDate.toLocalDate();
}
}
Any additional problems I suggest reading the full article for more information.
Other sources:
https://blog.tecsinapse.com.br/usando-localdate-java-8-no-hibernate4-jpa-2-1-972c463a44f9