/**
* {@inheritDoc}
*/
public void commit() throws HibernateException {
if ( !begun ) {
throw new TransactionException( "Transaction not successfully started" );
}
log.debug( "commit" );
boolean flush = !transactionContext.isFlushModeNever()
&& ( callback || !transactionContext.isFlushBeforeCompletionEnabled() );
if ( flush ) {
transactionContext.managedFlush(); //if an exception occurs during flush, user must call rollback()
}
if ( callback && newTransaction ) {
jdbcContext.beforeTransactionCompletion( this );
}
closeIfRequired();
if ( newTransaction ) {
try {
userTransaction.commit();
commitSucceeded = true;
log.debug( "Committed JTA UserTransaction" );
}
catch ( Exception e ) {
commitFailed = true; // so the transaction is already rolled back, by JTA spec
log.error( "JTA commit failed", e );
throw new TransactionException( "JTA commit failed: ", e );
}
finally {
afterCommitRollback();
}
}