-
28 febbraio 2021
-
90
views
LocalDate in java.sql.Date e viceversa
import javax.persistence.AttributeConverter; import javax.persistence.Converter; import java.sql.Date; import java.time.LocalDate; @Converter(autoApply = true) public class LocalDatePersistenceConverter implements AttributeConverter
{ @Override public java.sql.Date convertToDatabaseColumn(LocalDate entityValue) { return java.sql.Date.valueOf(entityValue); } @Override public LocalDate convertToEntityAttribute(java.sql.Date databaseValue) { return (databaseValue == null) ? null : databaseValue.toLocalDate(); } }
Esempio di entità:
@Entity public class Client{ @Id private long id; private LocalDate birthday; //тут должны быть геттеры и сеттеры }
GO TO FULL VERSION