Interface Transaction
- All Superinterfaces:
EntityTransaction
- All Known Subinterfaces:
TransactionImplementor
- All Known Implementing Classes:
TransactionImpl
Every resource-local transaction is associated with a Session
and begins with
an explicit call to SharedSessionContract.beginTransaction()
, or, almost 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:
- API Note:
- JPA doesn't allow an
EntityTransaction
to represent a JTA transaction. But when strict JPA transaction compliance is disabled, as it is by default, Hibernate allows an instance of this interface to represent the current JTA transaction context.
-
Method Summary
Modifier and TypeMethodDescriptionGet the current status of this transaction.@Nullable Integer
Retrieve the transaction timeout set for this instance.void
Attempt to mark the underlying transaction for rollback only.void
registerSynchronization
(Synchronization synchronization) Register a usersynchronization callback
for this transaction.void
setTimeout
(int seconds) Set the transaction timeout for any transaction started by any subsequent call toEntityTransaction.begin()
on this instance.Methods inherited from interface jakarta.persistence.EntityTransaction
begin, commit, getRollbackOnly, isActive, rollback, setRollbackOnly, setTimeout
-
Method Details
-
getStatus
TransactionStatus getStatus()Get the current status of this transaction. -
registerSynchronization
Register a usersynchronization callback
for this transaction.- Parameters:
synchronization
- TheSynchronization
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 toEntityTransaction.begin()
on this instance.- Parameters:
seconds
- The number of seconds before a timeout.
-
getTimeout
@Nullable Integer getTimeout()Retrieve the transaction timeout set for this instance. A negative integer indicates that no timeout has been set.- Specified by:
getTimeout
in interfaceEntityTransaction
- Returns:
- The timeout, in seconds.
-
markRollbackOnly
void markRollbackOnly()Attempt to mark the underlying transaction for rollback only.Unlike
EntityTransaction.setRollbackOnly()
, which is specified by JPA to throw when the transaction is inactive, this operation may be called on an inactive transaction, in which case it has no effect.- See Also:
-