title: Failed to store UUID into MySql database using hibernate/jpa
body: <p>I have a db table with this column:</p>
  
  <pre><code>uuid CHARACTER(36) NOT NULL
  </code></pre>
  
  <p>It's also a <code>UNIQUE INDEX (uuid)</code> but NOT a primary key.</p>
  
  <p>In the Entity class, the definition of the uuid column is like this:</p>
  
  <pre><code>    @GeneratedValue(generator = "system-uuid")
      @GenericGenerator(name = "system-uuid", strategy = "uuid")
      @Column(name = "uuid", updatable = false, nullable = false)
      private UUID uuid;
  </code></pre>
  
  <p>Then there is a Repository interface that spring data Repository interface:</p>
  
  <pre><code>@Repository
  public interface SaveRepository extends Repository&lt;CoreEvent, Integer&gt; {
  }
  </code></pre>
  
  <p>When I called saveRepository.save(), it complains that the uuid value is null:</p>
  
  <pre><code>org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL [n/a]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement
      at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:278)
      at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:244)
      at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:491)
      at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:59)
      at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:213)
  </code></pre>
  
  <p>... ...</p>
  
  <pre><code>Caused by: java.sql.SQLIntegrityConstraintViolationException: Column 'uuid' cannot be null
  </code></pre>
  
  <p>Did I miss anything in order to generate the uuid before saving the record to the db?</p>
  
  <p>Thanks in advance :)</p>