org.minijax.db.LocalDateConverter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of minijax-db Show documentation
Show all versions of minijax-db Show documentation
Minijax database and entity model
package org.minijax.db;
import java.sql.Date;
import java.time.LocalDate;
import javax.persistence.AttributeConverter;
import javax.persistence.Converter;
/**
* The LocalDateConverter class implements the JPA converter from
* Java LocalDate to Java SQL Date.
*/
@Converter
public class LocalDateConverter implements AttributeConverter {
@Override
public Date convertToDatabaseColumn(final LocalDate date) {
if (date == null) {
return null;
}
return Date.valueOf(date);
}
@Override
public LocalDate convertToEntityAttribute(final Date date) {
if (date == null) {
return null;
}
return date.toLocalDate();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy