Transaction management in spring (3)

Transaction management in spring (3)


transaction isolation level

        In theory, transactions should be completely isolated from each other to avoid problems caused by concurrent transactions. However, that would have a huge performance impact since transactions must run sequentially.

        In actual development, in order to improve performance, transactions will run at a lower isolation level.

        The isolation level of a transaction can be specified through the isolation transaction property

 

Transaction isolation levels supported by Spring


The isolation level of transactions is supported by the underlying database engine, not by the application or framework.

Two transaction isolation levels supported by Oracle: READ_COMMITED, SERIALIZABLE

Mysql supports 4 transaction isolation levels.

 

Set isolated transaction properties

When managing transactions declaratively with the @Transactional annotation, you can set the isolation level in the isolation attribute of @Transactional.


In transaction notifications, the isolation level can be specified in the <tx:method> element

 

Set the rollback transaction property

By default only unchecked exceptions (RuntimeException and Error type exceptions) will cause transaction rollback. Checked exceptions do not.

The rollback rules of a transaction can be defined by the rollbackFor and noRollbackFor attributes of the @Transactional annotation. These two attributes are declared as Class[] types, so multiple exception classes can be specified for these two attributes.

rollbackFor: must rollback when encountered

noRollbackFor: A set of exception classes that must not be rolled back when encountered

 

In transaction notifications, rollback rules can be specified in the <tx:method> element. If there are more than one exceptions, separate them with commas.


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325939692&siteId=291194637