## org.hibernate
Interface Transaction

All Known Subinterfaces:
  TransactionImplementor

All Known Implementing Classes:
  AbstractTransactionImpl, CMTTransaction, JdbcTransaction, JtaTransaction

    public interface Transaction

Defines the contract for abstracting applications from the configured underlying means of transaction management. 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 initiated by a call to `SharedSessionContract.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.

Implementers are not intended to be thread-safe.

Method Summary
`void` `begin()` Begin this transaction.
`void` `commit()` Commit this transaction.
`LocalStatus` `getLocalStatus()` Get the current local status of this transaction.
`int` `getTimeout()` Retrieve the transaction timeout set for this transaction.
`boolean` `isActive()` Is this transaction still active? Answers on a best effort basis.
`boolean` `isInitiator()` Is this transaction the initiator of any underlying transaction?
`boolean` `isParticipating()` Is Hibernate participating in the underlying transaction? Generally speaking this will be the same as `isActive()`.
`void` `registerSynchronization(Synchronization synchronization)` Register a user synchronization callback for this transaction.
`void` `rollback()` Rollback this transaction.
`void` `setTimeout(int seconds)` Set the transaction timeout for any transaction started by a subsequent call to `begin()` on this instance.
`boolean` `wasCommitted()` Was this transaction committed? Answers on a best effort basis.
`boolean` `wasRolledBack()` Was this transaction rolled back or set to rollback only? Answers on a best effort basis.

Method Detail

### isInitiator

    boolean isInitiator()

  Is this transaction the initiator of any underlying transaction?

  Returns:
    `true` if this transaction initiated the underlying transaction; `false` otherwise.

### begin

    void begin()

  Begin this transaction. No-op if the transaction has already been begun. Note that this is not necessarily symmetrical since usually multiple calls to `commit()` or `rollback()` will error.

  Throws:
    `HibernateException` - Indicates a problem beginning the transaction.

### commit

    void commit()

  Commit this transaction. This might entail a number of things depending on the context:
  - If this transaction is the `initiator`, `Session.flush()` the `Session` with which it is associated (unless `Session` is in `FlushMode.MANUAL`).
  - If this transaction is the `initiator`, commit the underlying transaction.
  - Coordinate various callbacks

  Throws:
    `HibernateException` - Indicates a problem committing the transaction.

### rollback

    void rollback()

  Rollback this transaction. Either rolls back the underlying transaction or ensures it cannot later commit (depending on the actual underlying strategy).

  Throws:
    `HibernateException` - Indicates a problem rolling back the transaction.

### getLocalStatus

    LocalStatus getLocalStatus()

  Get the current local status of this transaction.

  This only accounts for the local view of the transaction status. In other words it does not check the status of the actual underlying transaction.

  Returns:
    The current local status.

### isActive

    boolean isActive()

  Is this transaction still active?

  Answers on a best effort basis. For example, in the case of JDBC based transactions we cannot know that a transaction is active when it is initiated directly through the JDBC `Connection`, only when it is initiated from here.

  Returns:
    `true` if the transaction is still active; `false` otherwise.
  Throws:
    `HibernateException` - Indicates a problem checking the transaction status.

### isParticipating

    boolean isParticipating()

  Is Hibernate participating in the underlying transaction?

  Generally speaking this will be the same as `isActive()`.

  Returns:
    `true` if Hibernate is known to be participating in the underlying transaction; `false` otherwise.

### wasCommitted

    boolean wasCommitted()

  Was this transaction committed?

  Answers on a best effort basis. For example, in the case of JDBC based transactions we cannot know that a transaction was committed when the commit was performed directly through the JDBC `Connection`, only when the commit was done from this.

  Returns:
    `true` if the transaction is rolled back; `false` otherwise.
  Throws:
    `HibernateException` - Indicates a problem checking the transaction status.

### wasRolledBack

    boolean wasRolledBack()

  Was this transaction rolled back or set to rollback only?

  Answers on a best effort basis. For example, in the case of JDBC based transactions we cannot know that a transaction was rolled back when rollback was performed directly through the JDBC `Connection`, only when it was rolled back from here.

  Returns:
    true if the transaction is rolled back; false otherwise.
  Throws:
    `HibernateException` - Indicates a problem checking the transaction status.

### registerSynchronization

    void registerSynchronization(Synchronization synchronization)
                                 throws HibernateException

  Register a user synchronization callback for this transaction.

  Parameters:
    `synchronization` - The Synchronization callback to register.
  Throws:
    `HibernateException` - Indicates a problem registering the synchronization.

### setTimeout

    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.

### getTimeout

    int getTimeout()

  Retrieve the transaction timeout set for this transaction. A negative indicates no timeout has been set.

  Returns:
    The timeout, in seconds.

Copyright © 2001-2012 Red Hat, Inc. All Rights Reserved.