title: Transaction handling with spring data and JDBC Template
body: <p>I would like to do a batch delete without first making a Select for each object. I didn't find a way with spring data jpa and the entity manager to do this.For this reason I try the JDBC template.
  However, I get problems with the pageable.
  This code workes fine and all deletes are executed by batching. Unfortunately with an unnecessary select for each entity.</p>
  <pre><code>@Transactional
  public void deleteFoos() {
  
     Page&lt;Foo&gt; page = repository.findAll(PageRequest.of(0,50);
     Pageable pageable = null;
     do {
        if ( pageable != null ) {
           page = repository.findAll( pageable );
        }
        repository.deleteAll( page.getContent() );
     } while ( (pageable = page.nextPageable()) != Pageable.unpaged() );
  }
  </code></pre>
  <p>What I have tried now is to implement the whole thing directly with the JDBC template.</p>
  <pre><code>@Transactional
      public void deleteFoos() {
      
         Page&lt;Foo&gt; page = repository.findAll(PageRequest.of(0,50);
         Pageable pageable = null;
         do {
            if ( pageable != null ) {
               page = repository.findAll( pageable );
            }
            //repository.deleteAll( page.getContent() );
   jdbcTemplate.batchUpdate(
           &quot;DELETE FROM foo WHERE (id = ?)&quot;,
           page.getContent(),
           page.getTotalItems(),
           ( preparedStatement, argument ) -&gt; {
              preparedStatement.setObject( 1, argument.getId() );
           } );
         } while ( (pageable = page.nextPageable()) != Pageable.unpaged() );
      }
  </code></pre>
  <p>However, the third and fourth page is always empty. It seems the delete is executed directly. Auto commit is off, what else could be wrong?</p>
  <p>EDIT: Solution from Jens works fine: &quot;You can simply repeatedly request the first page and delete it.&quot;</p>