📕
Knowledge
  • Knowledge Repository
  • Java
    • Intro
    • Persistence
      • Java Persistence API (JPA)
        • Entity Manager
        • Transaction Management
        • Relationship Mapping
      • Java Transaction API (JTA)
    • Resources
  • Angular
    • Intro
    • Overview
    • CLI Commands
    • Directives
  • Tools
    • IDEs
      • IntelliJ
        • Shortcuts
  • Book Notes
    • Intro
    • Java A Beginner's Guide
      • Chapter 1. Java Fundamentals
      • Chapter 2. Data Types and Operators
      • Chapter 3. Program Control Statements
      • Chapter 4. Introducing Classes, Objects, and Methods
      • Chapter 5. More Data Types & Operators
      • Chapter 6. Closer Look At Methods and Classes
      • Chapter 7. Inheritance
      • Chapter 8. Packages & Interfaces
      • Chapter 9. Exception Handling
      • Chapter 10. Using I/O
    • Data Pipelines With Airflow
      • Chapter 1. Meet Airflow
      • Chapter 2. Anatomy Of a DAG
  • Course Notes
    • Intro
    • Spring: TDD With JUnit
Powered by GitBook
On this page

Was this helpful?

  1. Java
  2. Persistence
  3. Java Persistence API (JPA)

Transaction Management

PreviousEntity ManagerNextRelationship Mapping

Last updated 4 years ago

Was this helpful?

Transactions help to keep data in a consistent state, by grouping a series of operations that will either succeed or fail together. If successful, the transaction will be committed, if unsuccessful, any change will be rolled back automatically.

There are different ways to manage transactions. Below is an example of how this is performed using the EntityTransaction implementation of EntityManager.

    public void updateEntity(Entity entity) {
        EntityTransaction entityTransaction = entityManager.getTransaction();
        entityTransaction.begin();
        Entity entity1 = getEntityById(entity.getId());
        entity1.setEntityDescription(entity.getDescription());
        entityManager.flush();
        entityTransaction.commit()
    }

Please note, the above implementation is often replaced by using and applied using the @Transaction annotation.

Java Transaction API (JTA)