Interface IJpaTransaction
- All Superinterfaces:
AutoCloseable, Closeable
Common interface representing a JPA transaction context, which encapsulates a single JPA entity transaction. This
interface provides methods to manage the transaction lifecycle, including committing and rolling back transactions.
Note: Transactions need be set to be committed on close explicitly by calling commit().
Otherwise, the transaction will be rolled back automatically when the context is closed.
This interface extends Closeable to allow for automatic resource management, ensuring that the transaction
is properly closed and resources are released.
Note: This interface is designed for internal use only. Plugins should not use this interface. This interface may be moved to a different package in the future, so plugins should not depend on it.
- Since:
- 8.5.0
- Author:
- Norman Lorenz
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the JPA transaction context, committing the JPA transaction if set to do so.voidcommit()Marks the transaction to be committed when the transaction context isclosed.javax.persistence.EntityManagerem()Returns the JPA EntityManager associated with this transaction context.booleanisCommit()Checks if the transaction is marked to be committed when it is closed.voidrollback()Marks the transaction to be rolled back when the transaction context isclosed.
-
Method Details
-
close
void close()Closes the JPA transaction context, committing the JPA transaction if set to do so.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IllegalStateException- if the JPA EntityManager is closed or the JPA transaction is not activeRuntimeException- if the commit fails- See Also:
-
commit
void commit()Marks the transaction to be committed when the transaction context isclosed.- See Also:
-
em
javax.persistence.EntityManager em()Returns the JPA EntityManager associated with this transaction context.- Returns:
- the EntityManager
-
isCommit
boolean isCommit()Checks if the transaction is marked to be committed when it is closed.- Returns:
- true if the transaction is set to be committed, false otherwise
- See Also:
-
rollback
void rollback()Marks the transaction to be rolled back when the transaction context isclosed.- See Also:
-