Announcement Announcement Module
Collapse
No announcement yet.
HibernateCursorItemReader Transaction Strategy Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • HibernateCursorItemReader Transaction Strategy

    I have a domain Object Customer:

    Code:
    private boolean processed;
    private String name;
    etc...
    I am using a HibernateCursorItemReader to select all the Customers who have not been processed.

    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>
    Then in my Writer, I loop through the batch of 100 customers calling this method for each one:

    Code:
     
    
    @Transactional(  propagation = Propagation.MANDATORY)
    public void updateCustomer(Customer cust)
    {
      cust.setIsProcessed(true);
      customerDao.saveOrUpdate(cust);
    }
    This causes a deadlock, as the transaction on the updateCustomer method I think is conflicting with the transaction held open by the HibernateCursorItemReader?


    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?
    Last edited by mcbi4kh2; Feb 14th, 2013, 05:34 AM.
Working...
X