In case of Spring's declarative transaction management using annotations, there are five main attributes:
1. Propagation: This decides if method should execute within an existing/new or no transaction. Propagation.REQUIRED is the default value.
1. Propagation: This decides if method should execute within an existing/new or no transaction. Propagation.REQUIRED is the default value.

2. Isolation Level: This map to the isolation attribute of ACID properties. It decides the level of isolation between transactions. DEFAULT is the default value.
3. Read only: If an operation does not modify the data in database, but simply reads it then a read-only transaction can be used. Read only transactions provide the database with an opportunity to apply additional optimizations.As these optimizations need to be made at the start of the transaction the value of true is useful only in case of PROPAGATION_REQUIRED, PROPAGATION_REQUIRES_NEW and PROPAGATION_NESTED. The default value is false.
4.Transaction Timeout: To prevent long running transactions a timeout value can be set, which causes the transaction to rollback if it does not complete in the specified time. As the clock is started at the start of the transaction the value of true is useful only in case of PROPAGATION_REQUIRED, PROPAGATION_REQUIRES_NEW and PROPAGATION_NESTED.This value is in seconds. The default value is -1.
5. Rollback Rules: Spring commits a transaction when the method executes successfully. So accordingly to rollback a transaction, the method must fail. Failure is identified by exceptions. By default when a method throws a run-time exception, Spring will rollback the transaction. The behavior can be modified to include any exception checked or unchecked. Spring also allows us to specify exceptions on which the rollback should not occur.

No comments:
Post a Comment