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

de.alpharogroup.db.converter.LocalDateTimeConverter Maven / Gradle / Ivy

There is a newer version: 6.6
Show newest version
package de.alpharogroup.db.converter;

import java.time.Instant;
import java.time.LocalDateTime;
import java.util.Date;

import javax.persistence.AttributeConverter;
import javax.persistence.Converter;

/**
 * The class {@link LocalDateTimeConverter} is an attribute converter for {@link LocalDateTime} to {@link Date}.
 *
 * {@link LocalDateTime} the type of the entity attribute
 * {@link Date} the type of the database column
 */
@Converter(autoApply = true)
public class LocalDateTimeConverter implements AttributeConverter {

    /**
     * {@inheritDoc}
     */
    @Override
    public Date convertToDatabaseColumn(final LocalDateTime date) {
        final Instant instant = Instant.from(date);
        return Date.from(instant);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public LocalDateTime convertToEntityAttribute(final Date value) {
        final Instant instant = value.toInstant();
        return LocalDateTime.from(instant);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy