title: HSQLDB not throwing correct type of ConstraintViolationException with Spring JPA/Hibernate
body: <p>I have a Spring based JPA2 app with the Hibernate provider on HSQLDB. I'm trying to elegantly handle exceptions but am finding I am getting hibernate exceptions not JPA ones. For example:</p>
  
  <pre><code>   import javax.validation.ConstraintViolationException;
     ...
  
      @Override
      @Transactional
      public Result&lt;Document&gt; save(Document document) {
          try {
              store.persist(document);
              return new Success&lt;Document&gt;(document);
          }
          catch (EntityExistsException e) {
              return new Errors&lt;Document&gt;(DocumentError.DOCUMENT_ALREADY_EXISTS);
          }
          catch (ConstraintViolationException e) {
              return new Errors&lt;Document&gt;(DocumentError.CONSTRAINT_VOILATION);
          }
          catch (PersistenceException e) {
              return new Errors&lt;Document&gt;(DocumentError.UNKOWN_EXCEPTION);
          }
      }
  </code></pre>
  
  <p>Instead of javax.validation.ConstraintViolationException being thrown I catch a PersistenceException:</p>
  
  <blockquote>
    <p>javax.persistence.PersistenceException: org.hibernate.exception.ConstraintViolationException: could not insert: [Document]</p>
  </blockquote>
  
  <p>I have configured the JpaAdapter in my Spring configuration:</p>
  
  <pre><code>       &lt;bean id="dataSource"
                class="org.springframework.jdbc.datasource.DriverManagerDataSource"
                p:driverClassName="org.hsqldb.jdbcDriver"
                p:url="jdbc:hsqldb:file:target/db/intox"
                p:username="sa"
                p:password=""
                  /&gt;
  
          &lt;bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"
                p:entityManagerFactory-ref="entityManagerFactory"/&gt;
  
          &lt;bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
              &lt;property name="dataSource" ref="dataSource"/&gt;
              &lt;property name="jpaVendorAdapter" ref="jpaAdapter"/&gt;
              &lt;property name="loadTimeWeaver"&gt;
                  &lt;bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/&gt;
              &lt;/property&gt;
              &lt;property name="persistenceUnitName" value="p"/&gt;
          &lt;/bean&gt;
  
          &lt;bean id="entityManager" class="org.springframework.orm.jpa.support.SharedEntityManagerBean"&gt;
              &lt;property name="entityManagerFactory" ref="entityManagerFactory"/&gt;
          &lt;/bean&gt;
  
          &lt;bean id="jpaAdapter"
                class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"
                p:database="HSQL"
                p:showSql="false"/&gt;
  </code></pre>
  
  <p>Can anyone suggest how or why I am getting Hibernate exceptions rather than JPA (javax.persistence) ones?</p>
  
  <p>Additional info:<br>
  Spring 3.1.0.M2<br>
  Hibernate 3.5.4-Final<br>
  Hibernate Validator 4.1.0.Final<br>
  HSQLDB 2.0.0<br></p>