Package org.hibernate

Interface Transaction

  • All Superinterfaces:
    jakarta.persistence.EntityTransaction
    All Known Subinterfaces:
    TransactionImplementor
    All Known Implementing Classes:
    TransactionImpl

    public interface Transaction
    extends jakarta.persistence.EntityTransaction
    Represents a resource-local transaction, where resource-local is interpreted by Hibernate to mean any transaction under the control of Hibernate. That is to say, the underlying transaction might be a JTA transaction, or it might be a JDBC transaction, depending on how Hibernate is configured.

    Every resource-local transaction is associated with a Session and begins with an explicit call to SharedSessionContract.beginTransaction(), or, equivalently, with session.getTransaction().begin(), and ends with a call to EntityTransaction.commit() or EntityTransaction.rollback().

    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 concept of a database transaction. However, there is at most one uncommitted transaction associated with a given Session at any time.

    Note that this interface is never used to control container managed JTA transactions, and is not usually used to control transactions that affect multiple resources.

    A Transaction object is not threadsafe.

    See Also:
    SharedSessionContract.beginTransaction()
    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      TransactionStatus getStatus()
      Get the current status of this transaction.
      int getTimeout()
      Retrieve the transaction timeout set for this instance.
      default void markRollbackOnly()
      Attempt to mark the underlying transaction for rollback only.
      void registerSynchronization​(jakarta.transaction.Synchronization synchronization)
      Register a user synchronization callback for this transaction.
      void setTimeout​(int seconds)
      Set the transaction timeout for any transaction started by any subsequent call to EntityTransaction.begin() on this instance.
      • Methods inherited from interface jakarta.persistence.EntityTransaction

        begin, commit, getRollbackOnly, isActive, rollback, setRollbackOnly
    • Method Detail

      • registerSynchronization

        void registerSynchronization​(jakarta.transaction.Synchronization synchronization)
        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 any subsequent call to EntityTransaction.begin() on this instance.
        Parameters:
        seconds - The number of seconds before a timeout.
      • getTimeout

        int getTimeout()
        Retrieve the transaction timeout set for this instance. A negative integer indicates that no timeout has been set.
        Returns:
        The timeout, in seconds.
      • markRollbackOnly

        default void markRollbackOnly()
        Attempt to mark the underlying transaction for rollback only.