I use in my project annotation-based transaction management (I annotate some methods with @Transactional). I would like to set the isolation level globally (not by putting it as an argument to each @Transactional annotation).
Is it possible configure that in the XML? Currently my xml configuration contains
<tx:annotation-driven transaction-manager="txManager"/>
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
Is it possible to add the isolation somehow to tx:annotation-driven?
Spring's transaction management sets the transaction isolation on the Connection if you configure a non-default transaction isolation (by specifying it in a @Transactional annotation for example). If you can configure the transaction isolation of the connections while ensuring no other mechanism changes the transaction isolation of the connections, then you in effect globally set the transaction isolation used by the application.
For example, the Commons DBCP BasicDataSource class defines the defaultTransactionIsolation property to set the transaction isolation of connections returned from the pool:
<bean
id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
<property name="defaultTransactionIsolation">
<util:constant static-field="java.sql.Connection.TRANSACTION_READ_COMMITTED"/>
</property>
</bean>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With