title: Spring Boot with Hibernate: Auto-generating database schema with columns which can holds fractions of seconds
body: <p>I have a spring-boot project where I need to save the last modified time of entities with microseconds accuracy - actually, an audit property where entity version is kept. In my development environment, I use a MySQL database and MySQL's temporal types support fractions up to 6 digits. So I can define the respective column with <code>timestamp(6)</code> or <code>datetime(6)</code> when the schema is manually created.</p>
  
  <p>But I want the schema to be auto-generated with <code>spring.jpa.hibernate.ddl-auto=update</code> property. I know it's not a good practice in a production environment, but this project is going to be a template or seed for many other projects. So I need to keep it in generic form so that it does not depend on the underline database system.</p>
  
  <p>For MySQL, I can get it to work using <code>columnDefinition</code> argument of <code>@Column</code> annotation like below. </p>
  
  <pre><code>@Version
  @Column(columnDefinition= "datetime(6)")
  Timestamp version;
  </code></pre>
  
  <p>But this won't work in other databases where <code>datetime(6)</code> is not a valid temporal type.</p>
  
  <p>I tried auto-generating the particular database schema setting <code>scale</code> (<code>@Column(scale= 6)</code>) argument, but it just neglects the fraction part generates a column of type <code>datetime</code>, not <code>datetime(6)</code>.</p>
  
  <p>I'm curious if there is a way to do that, though I'm not aware.  </p>
  
  <p>Can you guys give me some input on this?</p>
  
  <h1>Update</h1>
  
  <p>@crizzis in his comment taught me that it is a matter of using correct <strong>hibernate.dialect</strong>. So, with <strong>org.hibernate.dialect.MySQL57Dialect</strong> I was able to auto-generate <strong>datetime(6)</strong> columns. Then I tried to control the number of digits in fraction part with <code>scale</code> argument without no success, it always have 6 digits. </p>
  
  <p>Now I'd like to know if it is possible without using <code>columnDefinition</code> argument inside <code>@Column</code> annotation.</p>