Top Description Methods
org.hibernate

public Interface Transaction

extends EntityTransaction
Known Direct Subinterfaces
org.hibernate.engine.transaction.spi.TransactionImplementor
Imports
jakarta.persistence.EntityTransaction, jakarta.transaction.Synchronization, org.hibernate.resource.transaction.spi.TransactionStatus

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 Session#beginTransaction(), or, equivalently, with session.getTransaction().begin(), and ends with a call to commit() or 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.

Authors
Anton van Straaten, Steve Ebersole
See Also
Session#beginTransaction()

Method Summary

Modifier and TypeMethod and Description
public TransactionStatus
getStatus()

Get the current status of this transaction.

public int

Returns:

The timeout, in seconds.
getTimeout
()

Retrieve the transaction timeout set for this instance.

public default void
markRollbackOnly()

Attempt to mark the underlying transaction for rollback only.

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

Register a user synchronization callback for this transaction.

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

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

Inherited from jakarta.persistence.EntityTransaction:
begincommitgetRollbackOnlyisActiverollbacksetRollbackOnly

Method Detail

getStatusback to summary
public TransactionStatus getStatus()

Get the current status of this transaction.

getTimeoutback to summary
public int getTimeout()

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

Returns:int

The timeout, in seconds.

markRollbackOnlyback to summary
public default void markRollbackOnly()

Attempt to mark the underlying transaction for rollback only.

registerSynchronizationback to summary
public void registerSynchronization(Synchronization synchronization)

Register a user synchronization callback for this transaction.

Parameters
synchronization:Synchronization

The Synchronization callback to register.

Exceptions
HibernateException:
Indicates a problem registering the synchronization.
setTimeoutback to summary
public void setTimeout(int seconds)

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

Parameters
seconds:int

The number of seconds before a timeout.