-
Couldn't load subscription status.
- Fork 0
Transaction
s-barabash edited this page Feb 15, 2024
·
1 revision
Transactions are essential for managing data consistency and integrity in enterprise applications.
- NOT_ACTIVE - The transaction has not yet been started.
- ACTIVE - The transaction has been started, but not yet completed.
- COMMITTED - The transaction has been completed successfully.
- ROLLED_BACK - The transaction has been rolled back.
- FAILED_COMMIT - The transaction attempted to commit, but failed.
- FAILED_ROLLBACK - The transaction attempted to rollback, but failed.
- Start a resource transaction
public void begin()- Commit the current transaction
public void commit()- Roll back the current resource transaction
public void rollback()- Return current transaction status
public TransactionStatus getStatus()public void saveEntity(Person person) {
Transaction transaction = session.getTransaction();
try {
transaction.begin();
session.persist(expectedPerson);
transaction.commit();
} catch (Exception e) {
transaction.rollback();
}
}