org.springframework.batch.item.ItemStreamException : Failed to initialize the reader
Hello,
I use distributed transactions with Bitronix and Spring batch. Here is the reader that causes the above exception:
Code:
<bean id="abonneItemReader" class="org.springframework.batch.item.database.JdbcCursorItemReader">
<property name="dataSource" ref="dataSourceJbm"/>
<property name="sql" value="select * FROM Abonne WHERE abonneConfirme = 1"/>
<property name="rowMapper" ref="abonneRowMapper"/>
</bean>
<bean id="dataSourceJbm" class="bitronix.tm.resource.jdbc.PoolingDataSource" init-method="init" destroy-method="close">
<property name="uniqueName" value="mysql_jbm" />
<property name="maxPoolSize" value="5" />
<property name="className" value="${database.driver}"/>
<property name="driverProperties">
<props>
<prop key="databaseName">jbm</prop>
<prop key="user">${database.username}</prop>
<prop key="password">${database.password}</prop>
<prop key="URL">${database.jbm.url}</prop>
</props>
</property>
</bean>
Here is the exception stack trace:
Code:
16:06:32.273 [main] ERROR o.s.batch.core.step.AbstractStep - Encountered an error executing the step
org.springframework.batch.item.ItemStreamException: Failed to initialize the reader
at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.open(AbstractItemCountingItemStreamItemReader.java:137) ~[spring-batch-infrastructure-2.1.8.RELEASE.jar:na]
at org.springframework.batch.item.support.CompositeItemStream.open(CompositeItemStream.java:93) ~[spring-batch-infrastructure-2.1.8.RELEASE.jar:na]
at org.springframework.batch.core.step.tasklet.TaskletStep.open(TaskletStep.java:301) ~[spring-batch-core-2.1.8.RELEASE.jar:na]
at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:192) ~[spring-batch-core-2.1.8.RELEASE.jar:na]
at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:135) [spring-batch-core-2.1.8.RELEASE.jar:na]
at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:61) [spring-batch-core-2.1.8.RELEASE.jar:na]
at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:60) [spring-batch-core-2.1.8.RELEASE.jar:na]
at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:144) [spring-batch-core-2.1.8.RELEASE.jar:na]
at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:124) [spring-batch-core-2.1.8.RELEASE.jar:na]
at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:135) [spring-batch-core-2.1.8.RELEASE.jar:na]
at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:281) [spring-batch-core-2.1.8.RELEASE.jar:na]
at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:120) [spring-batch-core-2.1.8.RELEASE.jar:na]
at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:48) [spring-core-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:114) [spring-batch-core-2.1.8.RELEASE.jar:na]
at org.springframework.batch.core.launch.support.CommandLineJobRunner.start(CommandLineJobRunner.java:349) [spring-batch-core-2.1.8.RELEASE.jar:na]
at org.springframework.batch.core.launch.support.CommandLineJobRunner.main(CommandLineJobRunner.java:574) [spring-batch-core-2.1.8.RELEASE.jar:na]
Caused by: org.springframework.jdbc.UncategorizedSQLException: Executing query; uncategorized SQLException for SQL [select * FROM Abonne WHERE abonneConfirme = 1]; SQL state [null]; error code [0]; error enlisting a JdbcConnectionHandle of a JdbcPooledConnection from datasource mysql_jbm in state ACCESSIBLE with usage count 1 wrapping com.mysql.jdbc.jdbc2.optional.JDBC4MysqlXAConnection@e2ecc7 on com.mysql.jdbc.jdbc2.optional.JDBC4ConnectionWrapper@867fc9; nested exception is java.sql.SQLException: error enlisting a JdbcConnectionHandle of a JdbcPooledConnection from datasource mysql_jbm in state ACCESSIBLE with usage count 1 wrapping com.mysql.jdbc.jdbc2.optional.JDBC4MysqlXAConnection@e2ecc7 on com.mysql.jdbc.jdbc2.optional.JDBC4ConnectionWrapper@867fc9
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:83) ~[spring-jdbc-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80) ~[spring-jdbc-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:80) ~[spring-jdbc-3.0.5.RELEASE.jar:3.0.5.RELEASE]
at org.springframework.batch.item.database.JdbcCursorItemReader.openCursor(JdbcCursorItemReader.java:130) ~[spring-batch-infrastructure-2.1.8.RELEASE.jar:na]
at org.springframework.batch.item.database.AbstractCursorItemReader.doOpen(AbstractCursorItemReader.java:401) ~[spring-batch-infrastructure-2.1.8.RELEASE.jar:na]
at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.open(AbstractItemCountingItemStreamItemReader.java:134) ~[spring-batch-infrastructure-2.1.8.RELEASE.jar:na]
... 15 common frames omitted
Caused by: java.sql.SQLException: error enlisting a JdbcConnectionHandle of a JdbcPooledConnection from datasource mysql_jbm in state ACCESSIBLE with usage count 1 wrapping com.mysql.jdbc.jdbc2.optional.JDBC4MysqlXAConnection@e2ecc7 on com.mysql.jdbc.jdbc2.optional.JDBC4ConnectionWrapper@867fc9
at bitronix.tm.resource.jdbc.JdbcConnectionHandle.enlistResource(JdbcConnectionHandle.java:86) ~[btm-2.1.2.jar:2.1.2]
at bitronix.tm.resource.jdbc.JdbcConnectionHandle.prepareStatement(JdbcConnectionHandle.java:289) ~[btm-2.1.2.jar:2.1.2]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.6.0_23]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:1.6.0_23]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.6.0_23]
at java.lang.reflect.Method.invoke(Method.java:616) ~[na:1.6.0_23]
at bitronix.tm.resource.jdbc.BaseProxyHandlerClass.invoke(BaseProxyHandlerClass.java:63) ~[btm-2.1.2.jar:2.1.2]
at $Proxy0.prepareStatement(Unknown Source) ~[na:na]
at org.springframework.batch.item.database.JdbcCursorItemReader.openCursor(JdbcCursorItemReader.java:119) ~[spring-batch-infrastructure-2.1.8.RELEASE.jar:na]
... 17 common frames omitted
Caused by: bitronix.tm.internal.BitronixSystemException: resource 'mysql_jbm' cannot be used outside XA transaction scope. Set allowLocalTransactions to true if you want to allow this and you know your resource supports this.
at bitronix.tm.resource.common.TransactionContextHelper.enlistInCurrentTransaction(TransactionContextHelper.java:79) ~[btm-2.1.2.jar:2.1.2]
at bitronix.tm.resource.jdbc.JdbcConnectionHandle.enlistResource(JdbcConnectionHandle.java:84) ~[btm-2.1.2.jar:2.1.2]
... 25 common frames omitted
Can anyone please help?
Regards,
Julien.