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:
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 ); } Or do another try-catch within the finally block and throw the original exception, like: 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) { // log e throw caughtException; }
}
Regards Sebastian
|