Top Description Methods
org.hibernate

public Interface Transaction

Known Direct Implementers
org.hibernate.transaction.JTATransaction, org.hibernate.transaction.CMTTransaction, org.hibernate.transaction.JDBCTransaction
Imports
javax.transaction.Synchronization

Allows the application to define units of work, while maintaining abstraction from the underlying transaction implementation (eg. JTA, JDBC).

A transaction is associated with a Session and is usually instantiated by a call to Session.beginTransaction(). A single session might span multiple transactions since the notion of a session (a conversation between the application and the datastore) is of coarser granularity than the notion of a transaction. However, it is intended that there be at most one uncommitted Transaction associated with a particular Session at any time.

Implementors are not intended to be threadsafe.
Author
Anton van Straaten
See Also
Session#beginTransaction(), org.hibernate.transaction.TransactionFactory

Method Summary

Modifier and TypeMethod and Description
public void
begin()

Begin a new transaction.

public void
commit()

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

public boolean

Returns:

boolean Treu if this local transaction is still active.
isActive
()

Is this transaction still active?

public void
registerSynchronization(Synchronization
The Synchronization callback to register.
synchronization
)

Register a user synchronization callback for this transaction.

public void
rollback()

Force the underlying transaction to roll back.

public void
setTimeout(int
The number of seconds before a timeout.
seconds
)

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

public boolean

Returns:

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

Check if this transaction was successfully committed.

public boolean

Returns:

boolean True if the transaction was rolled back via this local transaction; false otherwise.
wasRolledBack
()

Was this transaction rolled back or set to rollback only?

Method Detail

beginback to summary
public void begin() throws HibernateException

Begin a new transaction.

commitback to summary
public void commit() throws HibernateException

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

This method will commit the underlying transaction if and only if the underlying transaction was initiated by this object.
isActiveback to summary
public boolean isActive() throws HibernateException

Is this transaction still active?

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

Returns:boolean

boolean Treu if this local transaction is still active.

registerSynchronizationback to summary
public void registerSynchronization(Synchronization synchronization) throws HibernateException

Register a user synchronization callback for this transaction.

Parameters
synchronization:Synchronization

The Synchronization callback to register.

rollbackback to summary
public void rollback() throws HibernateException

Force the underlying transaction to roll back.

setTimeoutback to summary
public void setTimeout(int seconds)

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

Parameters
seconds:int

The number of seconds before a timeout.

wasCommittedback to summary
public boolean wasCommitted() throws HibernateException

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

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

wasRolledBackback to summary
public boolean wasRolledBack() throws HibernateException

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

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