I have a domain Object Customer:
I am using a HibernateCursorItemReader to select all the Customers who have not been processed.Code:private boolean processed; private String name; etc...
Then in my Writer, I loop through the batch of 100 customers calling this method for each one:Code:<bean id="customerReader" class="org.springframework.batch.item.database.HibernateCursorItemReader"> <property name="queryString" value="from Customer where processed = false" /> <property name="sessionFactory" ref="sessionFactory" /> <property name="fetchSize" value="100" /> <property name="useStatelessSession" value="true" /> </bean> <bean id="customerWriter" class="com.CustomerWriter"/> <batch:job id="customerProcessJob" > <batch:step id="customerProcessJob_step1" > <batch:tasklet transaction-manager="transactionManager" >> <batch:chunk reader="customerReader" writer="customerWriter" commit-interval="1"> </batch:chunk> </batch:tasklet> </batch:step> </batch:job>
This causes a deadlock, as the transaction on the updateCustomer method I think is conflicting with the transaction held open by the HibernateCursorItemReader?Code:@Transactional( propagation = Propagation.MANDATORY) public void updateCustomer(Customer cust) { cust.setIsProcessed(true); customerDao.saveOrUpdate(cust); }
As a test I called another DAO method, that has no interaction with the CUSTOMER table, which causes no deadlock and everything continues to process.
Is this possible, to update an object whilst cursing through it? Or is it something fundamentally wrong with my set up?


Reply With Quote
