Hi,
I have defined a job that reads from a MySQL database using HibernateCursorItemReader & writes each item to a JMS queue using an ItemWriterAdapter delegating to a custom bean method. XA integrity is required so I'm using Atomikos as the transanctionManager.
I am running into trouble when accessing the ScrollableResultSet next() in the reader. It appears there is no transaction to join..
My JTA debug indicates that transactions are being created/commited for each of the job respository meta data calls.. is this correct behaviour?Code:INFO [SimpleJobLauncher] Job: [org.springframework.batch.core.configuration.support.ClassPathXmlApplicationContextJo bFactory$ContextClosingJob] failed with the following parameters: [{}{}{}{}] com.atomikos.datasource.ResourceException: Error in resume() for XID: pmc_tm0001100046pmc_tm1 with errorCode -9 at com.atomikos.datasource.xa.XAResourceTransaction.resume(Unknown Source) at com.atomikos.jdbc.ConnectionProxy.invoke(Unknown Source) at $Proxy21.prepareStatement(Unknown Source)java:505)
If you haven't already guessed I'm new to Spring batch
I'm sure I've missed something in my config, can anyone spot anything obvious?
Any help/pointers much appreciated!
Code:<!-- ================= Batch Config ================= --> <bean id="jobRepository" class="org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean" > <property name="transactionManager" ref="transactionManager" /> <property name="isolationLevelForCreate" value="ISOLATION_DEFAULT" /> </bean> <bean id="myJob" class="org.springframework.batch.core.job.SimpleJob" > <property name="jobRepository" ref="jobRepository" /> <property name="steps"> <list> <bean id="myStep" class="org.springframework.batch.core.step.item.SimpleStepFactoryBean"> <property name="itemReader" ref="hibernateItemReader" /> <property name="itemWriter" ref="jmsEventWriter" /> <property name="transactionManager" ref="transactionManager" /> <property name="jobRepository" ref="jobRepository" /> <property name="commitInterval" value="1" /> </bean> </list> </property> </bean> <bean id="hibernateItemReader" class="org.springframework.batch.item.database.HibernateCursorItemReader"> <property name="sessionFactory" ref="hibernateSessionFactory" /> <property name="useStatelessSession" value="true" /> <property name="queryString" value="from Item" /> </bean> <bean id="jmsEventWriter" class="org.springframework.batch.item.adapter.ItemWriterAdapter"> <property name="targetObject" ref="jmsProcessor" /> <property name="targetMethod" value="sendJMS" /> </bean> <!-- ================= Atomikos Config ================= --> <bean id="atomikosTransactionManager" class="com.atomikos.icatch.jta.UserTransactionManager" init-method="init" destroy-method="close"> <property name="forceShutdown" value="true" /> <property name="transactionTimeout" value="300" /> <property name="startupTransactionService" value="true"/> </bean> <bean id="atomikosUserTransaction" class="com.atomikos.icatch.jta.UserTransactionImp"/> <bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"> <property name="transactionManager" ref="atomikosTransactionManager"/> <property name="userTransaction" ref="atomikosUserTransaction"/> </bean> <!-- ================= Hibernate Config ================= --> <properties> <property name="hibernate.connection.release_mode" value="after_transaction" /> <property name="hibernate.transaction.factory.class" value="org.hibernate.transaction.JTATransactionFactory"/> <property name="hibernate.transaction.manager_lookup_class" value="com.atomikos.icatch.jta.hibernate3.TransactionManagerLookup"/> <property name="hibernate.jdbc.use_scrollable_resultset" value="true" /> </properties> <!-- entityManagerFactory is a JPA EntityManager, so I access the underlying HibernateSessionFactory like this --> <bean id="hibernateSessionFactory" factory-bean="entityManagerFactory" factory-method="getSessionFactory" />



Reply With Quote
