All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.minijax.db.LocalDateConverter Maven / Gradle / Ivy

There is a newer version: 0.4.14
Show newest version
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