Spring Batch DataSourceTransactionManager在Oracle上失败 [英] Spring Batch DataSourceTransactionManager fails on Oracle

查看:818
本文介绍了Spring Batch DataSourceTransactionManager在Oracle上失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用WebLogic 10.3.3和Oracle 11g,并且在我从Spring切换时遇到一个奇怪的问题Spring ResourcelessTransactionManager (主要用于测试)到高效的 DataSourceTransactionManager 。首先我使用了WebLogics默认驱动程序 oracle.jdbc.xa.client.OracleXADataSource 但是这个失败了,因为Spring无法设置隔离级别 - 这也记录了此处

I'm using WebLogic 10.3.3 with Oracle 11g and face a weird problem with Spring Batch as soon as I'm switching from Spring ResourcelessTransactionManager (which is mainly for testing) to the productive DataSourceTransactionManager. First I used WebLogics default driver oracle.jdbc.xa.client.OracleXADataSource but this one fails because Spring can't set the isolation level - this is also documented here.

我很好,因为我不需要全局交易所以我切换到 oracle.jdbc.driver.OracleDriver 。现在我收到错误消息

I'm fine with that since I don't need global transactions anyway so I switched to oracle.jdbc.driver.OracleDriver. Now I'm getting the error message

ORA-01453: SET TRANSACTION must be first statement of transaction

我没有找到很多关于此的信息,有一个bug但是应该已经在Oracle 7中修复了很长时间前。看起来事务是在(?)实际作业被添加到JobRepository之前启动的,并且没有正确关闭或类似的事情。

I don't find a lot of information on this, there was a bug but that should have been fixed in Oracle 7 long time ago. It looks like a transaction is started before (?) the actual job gets added to the JobRepository and is not closed properly or something like that.

推荐答案

JobI能够通过将所有事务的隔离级别设置为 READ_COMMITTED 来解决此问题。默认情况下,Spring将其设置为 SERIALIZABLE ,这是非常严格的(但非常好)。虽然Oracle应该支持它,但这在我的机器上不起作用:

JobI was able to solve this by setting the Isolation level for all transactions to READ_COMMITTED. By default, Spring sets that to SERIALIZABLE which is very strict (but perfectly fine). This didn't work on my machine although Oracle should support it:

http://www.oracle.com/technetwork/issue-archive/2005/05-nov/o65asktom-082389.html

这是我的代码 - 首先是配置:

Here's my code - first for the configuration:

<bean id="jobRepository" class="org.springframework.batch.core.repository.support.JobRepositoryFactoryBean">
    <property name="transactionManager" ref="transactionManager" />
    <property name="dataSource" ref="dataSource" />
    <property name="isolationLevelForCreate" value="ISOLATION_READ_COMMITTED" />
</bean>

...这是针对作业本身的(简化):

...and this is for the job itself (simplified):

public class MyFancyBatchJob {
  @Transactional(isolation=Isolation.READ_COMMITTED)
  public void addJob() {
    JobParameters params = new JobParametersBuilder().toJobParameters();
    Job job = jobRegistry.getJob("myFancyJob");
    JobExecution execution = jobLauncher.run(job, params);
  }
}

这篇关于Spring Batch DataSourceTransactionManager在Oracle上失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆