public class

CMTTransaction

extends Object
implements Transaction
java.lang.Object
   ↳ org.hibernate.transaction.CMTTransaction

Class Overview

Implements a basic transaction strategy for CMT transactions. All work is done in the context of the container managed transaction.

The term 'CMT' is potentially misleading here; the pertinent point simply being that the transactions are being managed by something other than the Hibernate transaction mechanism.

Summary

Fields
protected final JDBCContext jdbcContext
protected final TransactionFactory.Context transactionContext
Public Constructors
CMTTransaction(JDBCContext jdbcContext, TransactionFactory.Context transactionContext)
Public Methods
void begin()
Begin a new transaction.
void commit()
Flush the associated Session and end the unit of work (unless we are in MANUAL.
javax.transaction.Transaction getTransaction()
Getter for property 'transaction'.
boolean isActive()
Is this transaction still active?

Again, this only returns information in relation to the local transaction, not the actual underlying transaction.

void registerSynchronization(Synchronization sync)
Register a user synchronization callback for this transaction.
void rollback()
Force the underlying transaction to roll back.
void setTimeout(int seconds)
Set the transaction timeout for any transaction started by a subsequent call to begin() on this instance.
boolean wasCommitted()
Check if this transaction was successfully committed.
boolean wasRolledBack()
Was this transaction rolled back or set to rollback only?

This only accounts for actions initiated from this local transaction.

[Expand]
Inherited Methods
From class java.lang.Object
From interface org.hibernate.Transaction

Fields

protected final JDBCContext jdbcContext

protected final TransactionFactory.Context transactionContext

Public Constructors

public CMTTransaction (JDBCContext jdbcContext, TransactionFactory.Context transactionContext)

Public Methods

public void begin ()

Begin a new transaction.

public void commit ()

Flush the associated Session and end the unit of work (unless we are in MANUAL.

This method will commit the underlying transaction if and only if the underlying transaction was initiated by this object.

public javax.transaction.Transaction getTransaction ()

Getter for property 'transaction'.

Returns
  • Value for property 'transaction'.
Throws
SystemException

public boolean isActive ()

Is this transaction still active?

Again, this only returns information in relation to the local transaction, not the actual underlying transaction.

Returns
  • boolean Treu if this local transaction is still active.

public void registerSynchronization (Synchronization sync)

Register a user synchronization callback for this transaction.

Parameters
sync The Synchronization callback to register.

public void rollback ()

Force the underlying transaction to roll back.

public void setTimeout (int seconds)

Set the transaction timeout for any transaction started by a subsequent call to begin() on this instance.

Parameters
seconds The number of seconds before a timeout.

public boolean wasCommitted ()

Check if this transaction was successfully committed.

This method could return false even after successful invocation of commit(). As an example, JTA based strategies no-op on commit() calls if they did not start the transaction; in that case, they also report wasCommitted() as false.

Returns
  • boolean True if the transaction was (unequivocally) committed via this local transaction; false otherwise.

public boolean wasRolledBack ()

Was this transaction rolled back or set to rollback only?

This only accounts for actions initiated from this local transaction. If, for example, the underlying transaction is forced to rollback via some other means, this method still reports false because the rollback was not initiated from here.

Returns
  • boolean True if the transaction was rolled back via this local transaction; false otherwise.