title: Does JpaPollingChannelAdapter have similar functionality to JdbcPollingChannelAdapter's UpdateSql?
body: <p>I have a small Spring Boot application which uses Spring Integration to query an Oracle database for records of a certain status.</p>
  
  <p>Initially I had a working POC using JdbcPollingChannelAdapter which also defined an update statement which changed the status of found records so they were not re-scanned.</p>
  
  <p>The application uses Hibernate and thus I wanted to replace the Jdbc implementation with a JPA approach.</p>
  
  <p>Thus I successfully implemented a JpaPollingChannelAdapter with a JpaExecutor to retrieve the results in entity form.</p>
  
  <p>What I am trying to achieve is similar behavior to the Jdbc approach which would update all found records in the same transaction as the poller.</p>
  
  <p>Is there a proper way to achieve this within the adapter or should I just use an entity dao within the message handler?</p>
  
  <p>Hopefully that makes sense.</p>
  
  <p><strong>Update</strong>:</p>
  
  <p>Looking <a href="http://docs.spring.io/spring-integration/reference/html/jpa.html#jpa-outbound-channel-adapter" rel="nofollow noreferrer">through the docs</a> I'm assuming I'll need to use an OutboundChannelAdapter or Gateway (versus the InboundChannelAdapter since it's for retrieval only).</p>
  
  <p>I guess my question then becomes how to properly wire that up, if I can do everything within a single handler, or if I need to define multiple channels, 1 to retrieve and the other to update the entity status.</p>
  
  <p>Here is some basic code:</p>
  
  <pre><code>@Configuration
  public class IntegrationConfiguration {
  
      private final Log log = LogFactory.getLog(getClass());
  
      @Autowired
      private DataSource dataSource;
  
      @Autowired
      private EntityManager entityManager;
  
      @Autowired
      private Reactor rootReactor;
  
      @Autowired
      private RunDao runDao;
  
      @Bean
      @InboundChannelAdapter(channel = "notificationChannel", poller = @Poller(fixedDelay = "60000", maxMessagesPerPoll = "-1"))
      public MessageSource&lt;?&gt; jpaMessageSource() {
          return new JpaPollingChannelAdapter(jpaSelectExecutor());
      }
  
      @Bean
      @Gateway(requestChannel = "notificationChannel")
      public void updateMessageStatus() {
          JpaOutboundGateway gateway = new JpaOutboundGateway(jpaUpdateExecutor());
          gateway.setGatewayType(OutboundGatewayType.UPDATING);
      }
  
      @Bean
      public JpaExecutor jpaSelectExecutor() {
          JpaExecutor executor = new JpaExecutor(this.entityManager);
          executor.setJpaQuery("select R from Run R where R.notificationStatus = 'NOT_SENT' and R.runStatus.status = 'COMPLETE' and R.runConfig.notificationRecipients is not null");
          executor.setEntityClass(Run.class);
          return executor;
      }
  
      @Bean
      public JpaExecutor jpaUpdateExecutor() {
          JpaExecutor executor = new JpaExecutor(this.entityManager);
          executor.setJpaQuery("update Run R set R.notificationStatus = 'SENDING' where R.RunId = :RunId");
          executor.setEntityClass(Run.class);
          return executor;
      }
  
      @Bean
      @ServiceActivator(inputChannel = "notificationChannel")
      public MessageHandler jpaMessageHandler() {
          MessageHandler handler = new MessageHandler() {
              @Override
              public void handleMessage(Message&lt;?&gt; message) throws MessagingException {
                  for (Run run : (ArrayList&lt;Run&gt;) message.getPayload()) {
                      rootReactor.notify("send-email-notification", Event.wrap(run));
                      //run.setNotificationStatus(Run.NotificationStatus.SENDING);
                      //runDao.merge(run);
                  }
              }
          };
  
          return handler;
      }
  
      @Bean
      public IntegrationFlow pollingAdapterFlow() {
          return IntegrationFlows
                  .from(jpaMessageSource())
                  .handle(jpaMessageHandler())
                  .get();
      }
  }
  </code></pre>