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