title: Spring batch Lock when Reader and Writer works with the same table
body: <p>We are evaluating spring batch (version 3.0.3), and for it we have made a simple data process </p>
  
  <p><strong>Our test:</strong></p>
  
  <p>We have 500k rows in a table, and we want to process it updating a field as a flag of "row processed"</p>
  
  <p>Our job definition is like this:</p>
  
  <pre><code>&lt;beans:beans xmlns="http://www.springframework.org/schema/batch"
      xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="
          http://www.springframework.org/schema/beans
          http://www.springframework.org/schema/beans/spring-beans.xsd
          http://www.springframework.org/schema/batch
          http://www.springframework.org/schema/batch/spring-batch.xsd"
      profile="job1"&gt;
  
      &lt;job id="job1"&gt;
          &lt;step id="step1"&gt;
              &lt;tasklet&gt;
                  &lt;chunk reader="itemReader"  writer="itemWriter"
                      commit-interval="#{jobParameters['commit.interval']?:'100'}" /&gt;     
              &lt;/tasklet&gt;
          &lt;/step&gt;
      &lt;/job&gt;
  </code></pre>
  
  <p>We are using a JdbcCursorItemReader as reader (query like SELECT field1, field2 FROM table WHERE field3 = '2Process') and a JdbcBatchItemWriter as writer (UPDATE table SET field3 = 'Processed' WHERE field1 = :field1 and field2 = :field2)</p>
  
  <p>Our database is a DB2/zOS configured with a lock by page in the table we are using</p>
  
  <p>We use Bitronix as Transaction Manager</p>
  
  <p>When we launch it, we are obtaing this Exception:</p>
  
  <pre><code>Caused by: com.ibm.db2.jcc.am.SqlException: Error for batch element #8: DB2 SQL Error: SQLCODE=-913, SQLSTATE=57033, SQLERRMC=00C9008E;00000302;DBABCD  .TSTABLE .X'000201', DRIVER=4.19.26
  </code></pre>
  
  <p>It seems that the exception occurs because the Tx of the reader is not the same that the Tx for the writer for the database. And we are having a block in page 201 for it.</p>
  
  <p>Obviously, if we change the isolation level of the select, adding with ur, the batch is finishing ok.</p>
  
  <p>Our question is, this database lock, could be a problem caused for transaction manager because bitronix doesn't support nested trasactions? Or it seems to be a problem with db2 database and the locking policy defined</p>
  
  <p>Also, we don't know if is a good practice having a spring batch with a step that reads and writes to the same table</p>
  
  <p>Edit: Sorry, you are right, big mistake in my explanation, <strong>db2/zOS</strong></p>