Chun Li
Chun Li

Reputation: 11

Setting the custom isolation levels for DataSourceTransactionManager

How to enable custom isolation levels for the DataSourceTransactionManager?

I have the following in my spring configuration file.

<bean id="transactionManager"class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="myDataDource"/>    
</bean>

<bean id="myTransactionProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" abstract="true" lazy-init="false" autowire="default" dependency-check="default">
  <property name="transactionManager">
     <ref bean="transactionManager" /> 
  </property>
  <property name="transactionAttributes">
     <props>
        <prop key="cancel">PROPAGATION_REQUIRED,ISOLATION_READ_UNCOMMITTED,timeout_25,-Exception</prop>
     </props>
  </property>
</bean> 

But when I try to run it, it gives me the following error.

org.springframework.transaction.InvalidIsolationLevelException: JtaTransactionManager does not support custom isolation levels by default - switch 'allowCustomIsolationLevels' to 'true'

I am not using the JtaTransactionManager, why I got a warning about this? And how do I enable the custom isolation level for the DataSourceTransactionManager? In documentation, it was mentioned that this class would support the custom isolation levels, but I didn't find any examples online. Most of it are only for the JtaTransactionManager. Just wonder if anyone can help me out for this. Thanks.

Upvotes: 0

Views: 3722

Answers (1)

Vinay Veluri
Vinay Veluri

Reputation: 6865

TransactionManager can be DataSourceTransactionManager or JtaTransactionManager or JpaTransactionManager, what ever may be, we can configure the Isolation Level using @Transactional annotation.

If the context file is enabled with <tx:annotation-driven /> which supports the annotations placed on the DAO or Service level, it recognizes the Transaction.

isolation attribute of @Transactional will allow you to configure them.

@Transactional(isolation = Isolation.READ_COMMITTED) public void save(Country country) { // do some operations }

reference : Isolation levels, Transactional

I'm not sure with configuring xml file

Hope this Helps. :)

Upvotes: 1

Related Questions