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

nl.vpro.persistence.InstantToTimestampConverter Maven / Gradle / Ivy

There is a newer version: 5.3.2
Show newest version
package nl.vpro.persistence;

import jakarta.persistence.AttributeConverter;
import jakarta.persistence.Converter;
import java.sql.Timestamp;
import java.time.Instant;

/**
 * @author Michiel Meeuwissen
 * @since 0.36
 */
@Converter(autoApply = true)
public class InstantToTimestampConverter implements AttributeConverter {

    @Override
    public Timestamp convertToDatabaseColumn(Instant instant) {
        return instant == null ? null : Timestamp.from(instant);
    }

    @Override
    public Instant convertToEntityAttribute(Timestamp timestamp) {
        return timestamp == null ? null : timestamp.toInstant();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy