title: How to get constraintName on DataIntegrityViolationException using H2 database?
body: <p>I'm using PostgreSQL on production and H2 on development.</p>
  
  <p>I handle <code>DataIntegrityViolationException</code> in a SpringBoot ControllerAdvice and I want to get the name of the constraint that drives to this exception.</p>
  
  <p>My table is defined like that :</p>
  
  <pre><code>@Table(name = "user", uniqueConstraints = {
      @UniqueConstraint(name = "users_unique_email_idx", columnNames = {"email"})
  })
  class User ...
  </code></pre>
  
  <p>When I use PostgreSQL it works perfectly. I get the cause of exception which is a <code>ConstraintViolationException</code> and then get the constraint name. Something like that :</p>
  
  <pre><code>((ConstraintViolationException)ex.getCause()).getConstraintName()
  </code></pre>
  
  <p>But using H2 Database I can't find a way to get the constraintName. The <code>DataIntegrityViolationException</code> doesn't contain the <code>ConstraintViolationException</code> or the constraintName. With H2 the error message is empty :</p>
  
  <pre><code>DataIntegrityViolationException:
    could not execute statement; SQL [n/a]; constraint [null];
  Caused by:
    JdbcSQLException: Violation dindex unique ou clé primaire: {0}
    Unique index or primary key violation: {0}; SQL statement:
  </code></pre>
  
  <p>Note : In my H2 <code>INFORMATION_SCHEMA.CONSTRAINTS</code> table my constraint on email field exists and has the good name (<code>users_unique_email_idx</code>)</p>
  
  <p>Is it a limitation of H2 Database ?<br>
  How can I enable constraint name in H2 ? </p>
  
  <p>Thanks ! </p>