From the course: Java Persistence with JPA

What is a transaction? - Java Tutorial

From the course: Java Persistence with JPA

What is a transaction?

- [Instructor] Let's talk about the database transaction. There are several phrases often used in reference to a database transaction. In the context of a database transaction, a commit refers to permanently saving data after a set of tentative changes. A commit ends a transaction within a relational database, and allows all other users to see your changes. On the other hand, a rollback is an operation that returns the database to the previous state prior to a commit. What's the importance of a database transaction? The JPA transaction determines when the new, modified, or deleted entity is synchronized with the database. Transactions keep data in a consistent state, allowing you to group several options, or what I previously referred to as a tentative change in a single unit that will all either fail or succeed together as a group. It's important to discuss the persistence context in relation to transaction management. What is the persistence context? In short, the persistence context is a named session of entities, and within the persistence context, the entity instances and their life cycle are managed. In an application ecosystem, there may be only one persistence context, and all entity managers within a transaction must use that same persistence context. JTA, Jakarta Transactions, formally known as the Java Transactions API, helps you to manage transactions. JTA gives us the ability to control transaction boundaries programmatically. This makes it very easy to see the boundaries of your transaction within your source code. The API allows you to start, commit, suspend, and rollback transactions seamlessly. Now that you've learned a little about JTA, let's dive deeper into how you manage that transaction in your code.

Contents