| org.hibernate.internal.ExceptionConverterImpl converts HibernateException into their JPA equivalents. In convertCommitException it checks if the Hibernate stack was bootstrapped via JPA or Hibernate natively, and only converts the exception if the stack was bootstrapped via JPA. However, the generic convert(HibernateException e, LockOptions lockOptions) method, does not consider whether the stack was bootstrapped via JPA. HHH-12666 Closed introduced an additional configuration flag, nativeExceptionHandling51Compliance, but there is an inconsistency in the treatment of HibernateException if isJpaBootstrap is false and nativeExceptionHandling51Compliance is also false (the default). The inconsistency results in some HibernateException being wrapped (if from a commit), and others not being (e.g. from a flush), so in the same application you can see a ConstraintViolationException and a PersistenceException containing a ConstraintViolationException. Ouch. I think nativeExceptionHandling51Compliance is redundant, and instead the wrapping behaviour should only be triggered by isJpaBootstrap. |