Spring's related configuration of "transactionAttributes"

spring关于“transactionAttributes”的相关配置

<bean id="baseTransactionProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
lazy-init="true" abstract="true">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
<property name="transactionAttributes">
<props>
<prop key="insert*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="update*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="delete*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean> 


PROPAGATION_REQUIRED--Supports the current transaction. Assuming that there is no current transaction, create a new transaction. This is the most common choice.
PROPAGATION_SUPPORTS--Supports the current transaction. Runs in non-transactional mode, assuming there are no current transactions.
PROPAGATION_MANDATORY--Supports the current transaction, assuming there is no current transaction. An exception is thrown.
PROPAGATION_REQUIRES_NEW--New transaction. Assume that there is currently a transaction. Suspend the current transaction.


PROPAGATION_NOT_SUPPORTED--Run the operation in a non-transactional manner, assuming a transaction currently exists. Suspend the current transaction.
PROPAGATION_NEVER--runs in non-transactional mode, throws an exception if there is a current transaction.
PROPAGATION_NESTED--Assume that there is currently a transaction. run within a nested transaction. Assume that there are currently no transactions. Then do something similar to PROPAGATION_REQUIRED. Methods to improve the query speed of SQL statements
Currently all transactions use the "PROPAGATION_REQUIRED" property value. Moreover, the operation authority of the control transaction is only read, so as to ensure that the data will not be updated during the query.
The "PROPAGATION_REQUIRED" property as defined above will cause transactions to be created for all operations. As a result, there will be a phenomenon that the update operation will also be performed when the JPA log is queried, which will result in low efficiency.
Change the operation of all queries to the transaction type "PROPAGATION_NEVER" (do not use transactions), the query efficiency will be improved immediately,
But worry about a problem at this time: for example, in a saveXXX() method. Assuming that the operation process of update, query, and update is used inside the method, will it not cause when the query is called. An exception is thrown because of the above configuration.


In addition
-Exception means that when an Exception is thrown, the transaction is rolled back. - means rollback + means submit
readonly is read only, set the operation permission to read only, generally used for query methods, optimization.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326760465&siteId=291194637