@Override protected void doCommit(DefaultTransactionStatus status) { JpaTransactionObject txObject = (JpaTransactionObject) status.getTransaction(); if (status.isDebug()) { logger.debug( "Committing JPA transaction on EntityManager [" + txObject.getEntityManagerHolder().getEntityManager() + "]"); } try { EntityTransaction tx = txObject.getEntityManagerHolder().getEntityManager().getTransaction(); tx.commit(); } catch (RollbackException ex) { if (ex.getCause() instanceof RuntimeException) { DataAccessException dex = getJpaDialect().translateExceptionIfPossible((RuntimeException) ex.getCause()); if (dex != null) { throw dex; } } throw new TransactionSystemException("Could not commit JPA transaction", ex); } catch (RuntimeException ex) { // Assumably failed to flush changes to database. throw DataAccessUtils.translateIfNecessary(ex, getJpaDialect()); } }
@Override protected void doSetRollbackOnly(DefaultTransactionStatus status) { JpaTransactionObject txObject = (JpaTransactionObject) status.getTransaction(); if (status.isDebug()) { logger.debug( "Setting JPA transaction on EntityManager [" + txObject.getEntityManagerHolder().getEntityManager() + "] rollback-only"); } txObject.setRollbackOnly(); }
@Override protected void doRollback(DefaultTransactionStatus status) { JpaTransactionObject txObject = (JpaTransactionObject) status.getTransaction(); if (status.isDebug()) { logger.debug( "Rolling back JPA transaction on EntityManager [" + txObject.getEntityManagerHolder().getEntityManager() + "]"); } try { EntityTransaction tx = txObject.getEntityManagerHolder().getEntityManager().getTransaction(); if (tx.isActive()) { tx.rollback(); } } catch (PersistenceException ex) { throw new TransactionSystemException("Could not roll back JPA transaction", ex); } finally { if (!txObject.isNewEntityManagerHolder()) { // Clear all pending inserts/updates/deletes in the EntityManager. // Necessary for pre-bound EntityManagers, to avoid inconsistent state. txObject.getEntityManagerHolder().getEntityManager().clear(); } } }
/* * @see * org.springframework.jdbc.datasource.DataSourceTransactionManager#doCommit * (org.springframework.transaction.support.DefaultTransactionStatus) */ public void doCommit(DefaultTransactionStatus status) throws TransactionException { CompensatingTransactionObject txObject = (CompensatingTransactionObject) status.getTransaction(); txObject.getHolder().getTransactionOperationManager().commit(); }