I was wondering if anyone could explain why validation exceptions are thrown differently with exactly the same code but with different drivers. When using HSQL a ConstraintViolationException is called from preInsert directly during a call to #persist. With PSQL the exception is not thrown from #persist but from preInsert during a #commit call. Furthermore, for HSQL the ConstraintViolationException is thrown raw from #persist while for PSQL it is wrapped in a RollbackException which is then wrapped in a TransactionSystemException.
Because of this, code I have written for HSQL has to be rewritten for PSQL. I could understand having to do this for database specific features but for Bean Validation, well I guess I'm not sure why the validate call happens in two different places. Also, are there good patterns for crafting Hibernate/JPA exception handling so that it can work with both drivers without looking redundant and ugly?
TIA
|