@transactional annotation

At a high level, Spring creates proxies for all the classes annotated with @Transactional – either on the class or on any of the methods. The proxy allows the framework to inject transactional logic before and after the running method – mainly for starting and committing the transaction

Here is what the above code is Doing:
1. The @Transactional annotation is used to mark a method or a class as transactional.
2. The @Transactional annotation can be used on a class or on a method.
3. If used on a class, all the public methods in the class will be transactional.
4. If used on a method, only that method will be transactional.
5. The @Transactional annotation can be used with the following parameters:

– propagation: This parameter is used to specify how the transaction should be propagated. The possible values are:

PROPAGATION_REQUIRED: If a transaction is not already started, a new one will be created. If a transaction is already started, it will be used. This is the default value.
PROPAGATION_SUPPORTS: If a transaction is already started, it will be used. If a transaction is not already started, no new transaction will be created.
PROPAGATION_MANDATORY: If a transaction is already started, it will be used. If a transaction is not already started, an exception will be thrown.
PROPAGATION_REQUIRES_NEW: A new transaction will always be created.
PROPAGATION_NOT_SUPPORTED: If a transaction is already started, it will be suspended. If a transaction is not already started, no new transaction will be created.
PROPAGATION_NEVER: If a transaction is already started, an exception will be thrown. If a transaction is not already started, no new transaction will be created.
PROPAGATION_NESTED: If a transaction is already started, a nested transaction will be created.

– isolation: This parameter is used to specify the isolation level of the transaction. The possible values are:

ISOLATION_DEFAULT: This is the default value. The isolation level is implementation specific.
ISOLATION_READ_UNCOMMITTED: This isolation level allows a transaction to read data that is not yet committed by other transactions.
ISOLATION_READ_COMMITTED: This isolation level only allows a transaction to read data that is already committed by other transactions.
ISOLATION_REPEATABLE_READ: This isolation level ensures that if a row is read multiple times within the same transaction, the same data will be read.
ISOLATION_SERIALIZABLE: This isolation level ensures that all the reads and writes within a transaction are completely isolated from all other transactions.

– timeout: This parameter is used to specify the maximum time that a transaction can run before it is automatically rolled back. The timeout is specified in seconds.
– readOnly: This parameter is used to specify whether the transaction is read-only. The possible values are true and false. The default value is false.
– rollbackFor: This parameter is used to specify the exception types that must cause the transaction to be rolled back.
– noRollbackFor: This parameter is used to specify the exception types that must not cause the transaction to be rolled back.