Results 1 to 1 of 1

Thread: HibernateCursorItemReader Transaction Strategy

  1. #1
    Join Date
    Nov 2008
    Posts
    14

    Default 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 at 04:34 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •