title: JpaPollingChannelAdapter with entity update at end
body: <p>I am working on the integration of a Vendor software that uses for interface a DB table mimicking a queue.
  Here is the JPA entity representation of such table:</p>
  <pre class="lang-java prettyprint-override"><code>@Data
  @Entity
  @Table(name = &quot;TASK&quot;)
  public static class Task implements Serializable {
  
      @Id
      @GeneratedValue(generator = &quot;TaskId&quot;)
      @SequenceGenerator(name = &quot;TaskId&quot;, sequenceName = &quot;TASK_SEQ&quot;, allocationSize = 50)
      @Column(name = &quot;ID&quot;)
      private BigInteger id;
  
      private Status status;
  
      private LocalDate processedDate;
  
      public enum Status {
          NEW, PROCESSED, ERROR
      }
  }
  </code></pre>
  <p>I would like to use Spring integration to poll NEW records from this table, handle them (typical use case is to transfom and post on a JMS queue), and then udpate the record with either:</p>
  <ul>
  <li>status PROCESSED if everything went fine</li>
  <li>status ERROR if an exception occured</li>
  </ul>
  <p>I tried to do so with JpaExecutor + JpaPollingChannelAdapter without much success. How would you recommend to tackle this case ?</p>
  <p>Here is how I started:</p>
  <pre class="lang-java prettyprint-override"><code>import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.context.annotation.Bean;
  import org.springframework.integration.config.EnableIntegration;
  import org.springframework.integration.dsl.IntegrationFlow;
  import org.springframework.integration.dsl.IntegrationFlows;
  import org.springframework.integration.dsl.Pollers;
  import org.springframework.integration.handler.GenericHandler;
  import org.springframework.integration.jpa.core.JpaExecutor;
  import org.springframework.integration.jpa.inbound.JpaPollingChannelAdapter;
  import org.springframework.stereotype.Component;
  
  @Component
  @EnableIntegration
  public class ExampleJob {
  
      @Autowired
      EntityManager entityManager;
  
      @Bean
      IntegrationFlow taskExecutorFlow() {
          JpaExecutor selectExecutor = new JpaExecutor(entityManager);
          selectExecutor.setJpaQuery(&quot;from Task where status = 'NEW'&quot;);
  
          JpaPollingChannelAdapter adapter = new JpaPollingChannelAdapter(selectExecutor);
  
          return IntegrationFlows
                  .from(adapter, c -&gt; c.poller(Pollers.fixedDelay(Duration.ofMinutes(5))).autoStartup(true))
                  .handle((task, headers) -&gt; task)
                  .get();
      }
  </code></pre>