Hi Adnan,
Create a JPA converter between LocalDate and String, for example:
package com.company.onboarding.entity;
import javax.persistence.AttributeConverter;
import javax.persistence.Converter;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
@Converter
public class DateToStringConverter implements AttributeConverter<LocalDate, String> {
@Override
public String convertToDatabaseColumn(LocalDate attribute) {
return attribute != null ? attribute.format(DateTimeFormatter.ISO_DATE) : null;
}
@Override
public LocalDate convertToEntityAttribute(String dbData) {
return dbData != null ? LocalDate.parse(dbData, DateTimeFormatter.ISO_DATE) : null;
}
}
The entity attribute should be of type LocalDate and the database column of type VARCHAR. Apply the converter on the attribute:
@Column(name = "DATE_", columnDefinition = "varchar(100)")
@Convert(converter = DateToStringConverter.class)
private LocalDate date;
public LocalDate getDate() {
return date;
}
public void setDate(LocalDate date) {
this.date = date;
}