oracle数据库使用org.mybatis.spring.batch.MyBatisBatchItemWriter时出现异常
Exception occurs when org.mybatis.spring.batch.MyBatisBatchItemWriter is used with oracle database
有人用过 MyBatisBatchItemWriter
oracle 数据库吗?
当我将提交间隔设置为 2 时,会引发违反协议的异常。
我用了 ResourcelessTrnasactionManager
和 MapJobRepositoryFactoryBean
.
与 MySQL 配合使用效果很好。
甚至 JdbcBatchItemWriter
也可以在 oracle 数据库中正常工作。
只有 MyBatisBatchItemWriter
与 oracle 数据库导致异常。
异常日志如下
[2015-01-20 17:27:53.194|DEBUG|o.s.b.core.step.tasklet.TaskletStep:TaskletStep.java:doInTransaction:437] Applying contribution: [StepContribution: read=240, written=0, filtered=0, readSkips=0, writeSkips=0, processSkips=0, exitStatus=EXECUTING]
[2015-01-20 17:27:53.194|DEBUG|o.s.b.s.t.ResourcelessTransactionManager:AbstractPlatformTransactionManager.java:handleExistingTransaction:471] Participating in existing transaction
[2015-01-20 17:27:53.195|DEBUG|o.s.b.core.step.tasklet.TaskletStep:TaskletStep.java:doInTransaction:451] Saving step execution before commit: StepExecution: id=3, version=7, name=putData, status=STARTED, exitStatus=EXECUTING, readCount=3240, filterCount=0, writeCount=0 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=7, rollbackCount=0, exitDescription=
[2015-01-20 17:27:53.195|DEBUG|o.s.b.s.t.ResourcelessTransactionManager:AbstractPlatformTransactionManager.java:handleExistingTransaction:471] Participating in existing transaction
[2015-01-20 17:27:53.196|DEBUG|org.mybatis.spring.SqlSessionUtils:Slf4jImpl.java:debug:47] Transaction synchronization flushing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@109a2025]
[2015-01-20 17:27:53.196|DEBUG|o.s.b.s.t.ResourcelessTransactionManager:AbstractPlatformTransactionManager.java:processCommit:753] Initiating transaction commit
[2015-01-20 17:27:53.196|DEBUG|o.s.b.s.t.ResourcelessTransactionManager:ResourcelessTransactionManager.java:doCommit:37] Committing resourceless transaction on [org.springframework.batch.support.transaction.ResourcelessTransactionManager$ResourcelessTransaction@288ca5f0]
[2015-01-20 17:27:53.196|DEBUG|org.mybatis.spring.SqlSessionUtils:Slf4jImpl.java:debug:47] Transaction synchronization committing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@109a2025]
[2015-01-20 17:27:53.196|DEBUG|org.mybatis.spring.SqlSessionUtils:Slf4jImpl.java:debug:47] Transaction synchronization closing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@109a2025]
[2015-01-20 17:27:53.196|DEBUG|o.s.jdbc.datasource.DataSourceUtils:DataSourceUtils.java:doReleaseConnection:327] Returning JDBC Connection to DataSource
[2015-01-20 17:27:53.197|ERROR|jdbc.sqltiming:Slf4jSpyLogDelegator.java:exceptionOccured:116] 7. Connection.close()
java.sql.SQLException: protocol violation
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:459) ~[ojdbc5-11.2.0.2.0.jar:11.2.0.2.0]
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:191) ~[ojdbc5-11.2.0.2.0.jar:11.2.0.2.0]
at oracle.jdbc.driver.T4C7Ocommoncall.doOLOGOFF(T4C7Ocommoncall.java:61) ~[ojdbc5-11.2.0.2.0.jar:11.2.0.2.0]
at oracle.jdbc.driver.T4CConnection.logoff(T4CConnection.java:498) ~[ojdbc5-11.2.0.2.0.jar:11.2.0.2.0]
at oracle.jdbc.driver.PhysicalConnection.close(PhysicalConnection.java:3915) ~[ojdbc5-11.2.0.2.0.jar:11.2.0.2.0]
at net.sf.log4jdbc.ConnectionSpy.close(ConnectionSpy.java:896) ~[log4jdbc-remix-0.2.7.jar:na]
at org.springframework.jdbc.datasource.DataSourceUtils.doCloseConnection(DataSourceUtils.java:341) [spring-jdbc-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.jdbc.datasource.DataSourceUtils.doReleaseConnection(DataSourceUtils.java:328) [spring-jdbc-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.jdbc.datasource.DataSourceUtils.releaseConnection(DataSourceUtils.java:294) [spring-jdbc-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.jdbc.datasource.DataSourceUtils$ConnectionSynchronization.afterCompletion(DataSourceUtils.java:476) [spring-jdbc-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.transaction.support.TransactionSynchronizationUtils.invokeAfterCompletion(TransactionSynchronizationUtils.java:168) [spring-tx-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.transaction.support.AbstractPlatformTransactionManager.invokeAfterCompletion(AbstractPlatformTransactionManager.java:994) [spring-tx-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.transaction.support.AbstractPlatformTransactionManager.triggerAfterCompletion(AbstractPlatformTransactionManager.java:969) [spring-tx-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:800) [spring-tx-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:724) [spring-tx-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:148) [spring-tx-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.batch.core.step.tasklet.TaskletStep.doInChunkContext(TaskletStep.java:271) [spring-batch-core-3.0.2.RELEASE.jar:3.0.2.RELEASE]
at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:77) [spring-batch-core-3.0.2.RELEASE.jar:3.0.2.RELEASE]
at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:368) [spring-batch-infrastructure-3.0.2.RELEASE.jar:3.0.2.RELEASE]
at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215) [spring-batch-infrastructure-3.0.2.RELEASE.jar:3.0.2.RELEASE]
at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:144) [spring-batch-infrastructure-3.0.2.RELEASE.jar:3.0.2.RELEASE]
at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:257) [spring-batch-core-3.0.2.RELEASE.jar:3.0.2.RELEASE]
at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:198) [spring-batch-core-3.0.2.RELEASE.jar:3.0.2.RELEASE]
at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:148) [spring-batch-core-3.0.2.RELEASE.jar:3.0.2.RELEASE]
at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:64) [spring-batch-core-3.0.2.RELEASE.jar:3.0.2.RELEASE]
at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:67) [spring-batch-core-3.0.2.RELEASE.jar:3.0.2.RELEASE]
at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:165) [spring-batch-core-3.0.2.RELEASE.jar:3.0.2.RELEASE]
at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:144) [spring-batch-core-3.0.2.RELEASE.jar:3.0.2.RELEASE]
at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:134) [spring-batch-core-3.0.2.RELEASE.jar:3.0.2.RELEASE]
at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:304) [spring-batch-core-3.0.2.RELEASE.jar:3.0.2.RELEASE]
at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:135) [spring-batch-core-3.0.2.RELEASE.jar:3.0.2.RELEASE]
at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:49) [spring-core-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:128) [spring-batch-core-3.0.2.RELEASE.jar:3.0.2.RELEASE]
at com.skplanet.storeplatform.batch.sac.common.main.BasicBatchRunnerMain.run(BasicBatchRunnerMain.java:60) [classes/:na]
at com.skplanet.storeplatform.batch.sac.common.main.BasicBatchRunnerMain.main(BasicBatchRunnerMain.java:45) [classes/:na]
[2015-01-20 17:27:53.197|DEBUG|o.s.jdbc.datasource.DataSourceUtils:DataSourceUtils.java:releaseConnection:297] Could not close JDBC Connection
这是mybatis的bug。现在,在映射器文件中将 mybatis 标记从 <insert>
更改为 <update>
。
有人用过 MyBatisBatchItemWriter
oracle 数据库吗?
当我将提交间隔设置为 2 时,会引发违反协议的异常。
我用了 ResourcelessTrnasactionManager
和 MapJobRepositoryFactoryBean
.
与 MySQL 配合使用效果很好。
甚至 JdbcBatchItemWriter
也可以在 oracle 数据库中正常工作。
只有 MyBatisBatchItemWriter
与 oracle 数据库导致异常。
异常日志如下
[2015-01-20 17:27:53.194|DEBUG|o.s.b.core.step.tasklet.TaskletStep:TaskletStep.java:doInTransaction:437] Applying contribution: [StepContribution: read=240, written=0, filtered=0, readSkips=0, writeSkips=0, processSkips=0, exitStatus=EXECUTING]
[2015-01-20 17:27:53.194|DEBUG|o.s.b.s.t.ResourcelessTransactionManager:AbstractPlatformTransactionManager.java:handleExistingTransaction:471] Participating in existing transaction
[2015-01-20 17:27:53.195|DEBUG|o.s.b.core.step.tasklet.TaskletStep:TaskletStep.java:doInTransaction:451] Saving step execution before commit: StepExecution: id=3, version=7, name=putData, status=STARTED, exitStatus=EXECUTING, readCount=3240, filterCount=0, writeCount=0 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=7, rollbackCount=0, exitDescription=
[2015-01-20 17:27:53.195|DEBUG|o.s.b.s.t.ResourcelessTransactionManager:AbstractPlatformTransactionManager.java:handleExistingTransaction:471] Participating in existing transaction
[2015-01-20 17:27:53.196|DEBUG|org.mybatis.spring.SqlSessionUtils:Slf4jImpl.java:debug:47] Transaction synchronization flushing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@109a2025]
[2015-01-20 17:27:53.196|DEBUG|o.s.b.s.t.ResourcelessTransactionManager:AbstractPlatformTransactionManager.java:processCommit:753] Initiating transaction commit
[2015-01-20 17:27:53.196|DEBUG|o.s.b.s.t.ResourcelessTransactionManager:ResourcelessTransactionManager.java:doCommit:37] Committing resourceless transaction on [org.springframework.batch.support.transaction.ResourcelessTransactionManager$ResourcelessTransaction@288ca5f0]
[2015-01-20 17:27:53.196|DEBUG|org.mybatis.spring.SqlSessionUtils:Slf4jImpl.java:debug:47] Transaction synchronization committing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@109a2025]
[2015-01-20 17:27:53.196|DEBUG|org.mybatis.spring.SqlSessionUtils:Slf4jImpl.java:debug:47] Transaction synchronization closing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@109a2025]
[2015-01-20 17:27:53.196|DEBUG|o.s.jdbc.datasource.DataSourceUtils:DataSourceUtils.java:doReleaseConnection:327] Returning JDBC Connection to DataSource
[2015-01-20 17:27:53.197|ERROR|jdbc.sqltiming:Slf4jSpyLogDelegator.java:exceptionOccured:116] 7. Connection.close()
java.sql.SQLException: protocol violation
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:459) ~[ojdbc5-11.2.0.2.0.jar:11.2.0.2.0]
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:191) ~[ojdbc5-11.2.0.2.0.jar:11.2.0.2.0]
at oracle.jdbc.driver.T4C7Ocommoncall.doOLOGOFF(T4C7Ocommoncall.java:61) ~[ojdbc5-11.2.0.2.0.jar:11.2.0.2.0]
at oracle.jdbc.driver.T4CConnection.logoff(T4CConnection.java:498) ~[ojdbc5-11.2.0.2.0.jar:11.2.0.2.0]
at oracle.jdbc.driver.PhysicalConnection.close(PhysicalConnection.java:3915) ~[ojdbc5-11.2.0.2.0.jar:11.2.0.2.0]
at net.sf.log4jdbc.ConnectionSpy.close(ConnectionSpy.java:896) ~[log4jdbc-remix-0.2.7.jar:na]
at org.springframework.jdbc.datasource.DataSourceUtils.doCloseConnection(DataSourceUtils.java:341) [spring-jdbc-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.jdbc.datasource.DataSourceUtils.doReleaseConnection(DataSourceUtils.java:328) [spring-jdbc-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.jdbc.datasource.DataSourceUtils.releaseConnection(DataSourceUtils.java:294) [spring-jdbc-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.jdbc.datasource.DataSourceUtils$ConnectionSynchronization.afterCompletion(DataSourceUtils.java:476) [spring-jdbc-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.transaction.support.TransactionSynchronizationUtils.invokeAfterCompletion(TransactionSynchronizationUtils.java:168) [spring-tx-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.transaction.support.AbstractPlatformTransactionManager.invokeAfterCompletion(AbstractPlatformTransactionManager.java:994) [spring-tx-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.transaction.support.AbstractPlatformTransactionManager.triggerAfterCompletion(AbstractPlatformTransactionManager.java:969) [spring-tx-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:800) [spring-tx-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:724) [spring-tx-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:148) [spring-tx-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.batch.core.step.tasklet.TaskletStep.doInChunkContext(TaskletStep.java:271) [spring-batch-core-3.0.2.RELEASE.jar:3.0.2.RELEASE]
at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:77) [spring-batch-core-3.0.2.RELEASE.jar:3.0.2.RELEASE]
at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:368) [spring-batch-infrastructure-3.0.2.RELEASE.jar:3.0.2.RELEASE]
at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215) [spring-batch-infrastructure-3.0.2.RELEASE.jar:3.0.2.RELEASE]
at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:144) [spring-batch-infrastructure-3.0.2.RELEASE.jar:3.0.2.RELEASE]
at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:257) [spring-batch-core-3.0.2.RELEASE.jar:3.0.2.RELEASE]
at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:198) [spring-batch-core-3.0.2.RELEASE.jar:3.0.2.RELEASE]
at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:148) [spring-batch-core-3.0.2.RELEASE.jar:3.0.2.RELEASE]
at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:64) [spring-batch-core-3.0.2.RELEASE.jar:3.0.2.RELEASE]
at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:67) [spring-batch-core-3.0.2.RELEASE.jar:3.0.2.RELEASE]
at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:165) [spring-batch-core-3.0.2.RELEASE.jar:3.0.2.RELEASE]
at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:144) [spring-batch-core-3.0.2.RELEASE.jar:3.0.2.RELEASE]
at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:134) [spring-batch-core-3.0.2.RELEASE.jar:3.0.2.RELEASE]
at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:304) [spring-batch-core-3.0.2.RELEASE.jar:3.0.2.RELEASE]
at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:135) [spring-batch-core-3.0.2.RELEASE.jar:3.0.2.RELEASE]
at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:49) [spring-core-3.2.2.RELEASE.jar:3.2.2.RELEASE]
at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:128) [spring-batch-core-3.0.2.RELEASE.jar:3.0.2.RELEASE]
at com.skplanet.storeplatform.batch.sac.common.main.BasicBatchRunnerMain.run(BasicBatchRunnerMain.java:60) [classes/:na]
at com.skplanet.storeplatform.batch.sac.common.main.BasicBatchRunnerMain.main(BasicBatchRunnerMain.java:45) [classes/:na]
[2015-01-20 17:27:53.197|DEBUG|o.s.jdbc.datasource.DataSourceUtils:DataSourceUtils.java:releaseConnection:297] Could not close JDBC Connection
这是mybatis的bug。现在,在映射器文件中将 mybatis 标记从 <insert>
更改为 <update>
。