@transactional comment Under what circumstances would fail, and why?

 

First, the features:

1, generally in the service Riga @Transactional annotation is not recommended on the interface to add such comment after the addition of this spring will be included in the management of affairs, each business method execution, will open a transaction, but are in the same management mechanism.
2, @ Transactional annotation can be applied only to the public modifier, other modifier does not work, but not an error.
3. By default, this comment will be unchecked exceptions rollback on checked exceptions are not rolled back.

What is unchecked, checked what is it?

In layman's terms, the compiler can detect is checked, undetectable is unchecked.
Error or derived from a RuntimeException (such as a null pointer, 1/0) is referred to as abnormal unchecked exceptions.
Inherited from Exception unusually collectively referred to as checked exceptions, such as IOException, TimeoutException and so on.
4, read-only transactions:
the @Transactional (propagation = Propagation.NOT_SUPPORTED, readOnly = to true)
read-only flag only when the application starts a transaction, or even configuration will be ignored.
Start the transaction will increase the thread overhead, because the database shared read and locked (with related specifically to the type of database and transaction isolation level). Typically, only read data, without having to set the read-only transactions and additional system overhead.

Two: transaction propagation mode

Propagation enumerating various transaction propagation mode, part listed below:

1, REQUIRED (default mode): business methods need to run in a container. If the method is running, already in a transaction, then added to this transaction, or create a new own affairs.

2, NOT_SUPPORTED: Statement method does not require the transaction. If the method is not associated with a transaction, the container does not open his affairs, if the method is called in a transaction, the transaction will be suspended, after the end of the call, the original transaction will resume execution.

3, REQUIRESNEW: whether or not there is a transaction, the method confluence launched a new business for themselves. If the method is already running in a transaction, the original transaction suspension, a new transaction is created.

4, MANDATORY: This method can only be in an existing transaction execution, business methods can not initiate their own affairs. If called without a transaction environment, the container throws an exception.

5, SUPPORTS: This method is called within a transaction scope, the method becomes part of the transaction. If the method is called outside the scope of a transaction, the method executes without a transaction environment.

6, NEVER: This method must not be executed within a transaction scope. If you throw an exception. Only the method is not associated with any transaction, perform the normal.

7, NESTED: a transaction if there is an active, run in a nested transaction. If there is no active transaction, press execute REQUIRED property. It uses a separate transaction, the transaction has multiple save points can be rolled back. Rollback internal affairs will not affect the external affairs. Only the onset of DataSourceTransactionManager transaction manager.

Third, the notes do not solve the problem rollback

1, check is not public
2, abnormalities is not unchecked exceptions
3, if the abnormality is checked like rollback, then the annotation can indicate the type of exception
@Transactional (rollbackFor = Exception.class)

Guess you like

Origin www.cnblogs.com/eryun/p/12017262.html