My entity has this attribute...
@Convert(converter = LocalDateTimeAtributeConverter.class)
@Column(name="dthr_ult_atualizacao")
private LocalDateTime ultimaAtualizacao;
In the server, the column is created by the JPA as:
dthr_ult_atualizacao (datetime2(7), null)
By code, I save the value below in this column:
2016-05-09T15:20:00.357
When I do a Select direct in the database, the value is correct:
2016-05-09 15:20:00.3570000
But when I recover this value by JPA, the value is wrong:
2016-05-07T15:20:00.357
Note that the day is wrong in two days.
So, if I change manually the data type, all work fine. What is wrong?
My converter:
import java.time.LocalDateTime;
import javax.persistence.AttributeConverter;
import javax.persistence.Converter;
@Converter
public class LocalDateTimeAtributeConverter implements AttributeConverter<LocalDateTime, java.sql.Timestamp> {
@Override
public java.sql.Timestamp convertToDatabaseColumn(LocalDateTime entityValue)
{
if (entityValue != null) {
return java.sql.Timestamp.valueOf(entityValue);
}
return null;
}
@Override
public LocalDateTime convertToEntityAttribute(java.sql.Timestamp databaseValue) {
if (databaseValue != null) {
return databaseValue.toLocalDateTime();
}
return null;
}
}
I am using Microsofr jdbc42 with wildfly 9