According to the JPA spec the ConstraintViolationException should be thrown. What would be the correct way to fix this? Put the transaction complete notifications into the try block, like: {code} try { if ( flush ) { LOG.trace( "Automatically flushing session" ); transactionCoordinator.getTransactionContext().managedFlush(); } transactionCoordinator.sendBeforeTransactionCompletionNotifications( null ); transactionCoordinator.getTransactionContext().beforeTransactionCompletion( null ); } catch ( RuntimeException re ) { setRollbackOnly(); throw exceptionMapper.mapManagedFlushFailure( "error during managed flush", re ); } {code} Or do another try-catch within the finally block and throw the original exception, like: {code} try { if ( flush ) { LOG.trace( "Automatically flushing session" ); transactionCoordinator.getTransactionContext().managedFlush(); } } catch ( RuntimeException re ) { setRollbackOnly(); caughtException = exceptionMapper.mapManagedFlushFailure( "error during managed flush", re ); throw caughtException; } finally { try{ transactionCoordinator.sendBeforeTransactionCompletionNotifications( null ); transactionCoordinator.getTransactionContext().beforeTransactionCompletion( null ); } catch (RuntimeException e) { if (caughtException == null) throw exceptionMapper.mapManagedFlushFailure( "error during managed flush", e ); else { // log e exceptionMapper.mapManagedFlushFailure( "error during managed flush", e ); throw caughtException; } } } {code} Regards Sebastian
|