JPA transaction handling in JBStrap
Database modifications in a multi-user environment can easily result in an inconsistent database state. To avoid this, database management systems use transactions. A transaction always starts from a consistent database state and contains a series of modifications that end up with a consistent database state again.
The database transaction always starts with initiating the transaction. The data manipulation instructions executed within the transaction are part of the transaction itself. There are two ways to close a transaction. A commit statement completes the transaction, after which each user will see a consistent state in the database. A rollback statement rolls back the transaction and users continue to see a consistent state before transaction initiation.
In JBStrap, all data management operations support the use of transactions. You can use database transactions with JPA DAO, DataDescriptor s , and even with data management components. Within a database transaction, you can write and read data, but you can even run native SQL.
How to Handle Data by Using JPA DAO API
All JPA DAO features support transaction management. If we handle modifications in a transaction, all modifications to the transaction can be finalized or rolled back at the same time. If a transaction statement is not executed due to an error, the entire transaction will be rolled back.
In the example above, your bank account balance will only be changed if all transactions have been completed. While the calculation is in progress, everyone except the modifying user will see the original A and B bank balance. When the transaction is finalized with the commit statement, all users will see the modified balances.
How to handle data in a transaction using DataDescriptors
The transaction handling remains is the same for DataDescriptor s as well. The same rules and principles apply to a transaction as when using JPA DAO API, that is, operations within a transaction results are only visible in the scope of the transaction and only after the transaction is closed.