title: Is there any way to map MySql TIMESTAMP to java.lang.Long?
body: <p>So I have this object saved to the database with one property being <code>dateCreated</code> which is, of course, saved as MySQL timestamp. But while sending the data to the client, I want to be in milliseconds. Right now, I've mapped it to the <code>Date</code> object and converting it to milliseconds further. But I thought, what if I could map my POJO in such a way that it retrieves values in milliseconds. Here is what I've tried.</p>
  <p>OmsJob:</p>
  <pre class="lang-java prettyprint-override"><code>@Entity
  @EntityListeners(PreventAnyUpdate.class)
  @ConfigurationProperties(&quot;omsjob&quot;)
  @Table(name = &quot;OMSJob&quot;)
  public class OmsJob {
  
      @Id
      @NotNull
      @Column(name = &quot;jobId&quot;)
      private String id;
  
      @NotNull
      private Long dateCreated; // If I map this property to Date, it works fine
  
  }
  </code></pre>
  <p>I thought I'll add a custom converter that'll convert <code>java.util.Date</code> or <code>java.sql.Date</code> to milliseconds. But it isn't working:</p>
  <pre class="lang-java prettyprint-override"><code>@Component
  @ConfigurationPropertiesBinding
  public class DateConverter implements Converter&lt;Date, Long&gt; {
  
      @Override
      public Long convert(Date date) {
          return date.getTime();
      }
  }
  </code></pre>
  <p>The error I am getting is pretty obvious but is there any way to achieve what I am trying to?</p>
  <pre class="lang-sh prettyprint-override"><code>ERROR 229770 --- [           main] o.h.engine.jdbc.spi.SqlExceptionHelper   : Unsupported conversion from TIMESTAMP to java.lang.Long
  </code></pre>