title: Spring Integration: javax.persistence.TransactionRequiredException: no transaction is in progress
body: <p>I would like to achieve the following in Spring Integration:</p>
  
  <ol>
  <li>A message is received in an input channel</li>
  <li>This goes through a Transformer which persists it in the DB and thus gives it an ID</li>
  <li>it goes on to further processing into some external systems.</li>
  </ol>
  
  <p>My transformer looks like this:</p>
  
  <pre><code>@PersistenceContext
  private EntityManager em;
  
  @Transactional
  public ServiceResponse persistBatchOperation(List&lt;OperationDTO&gt; operations) {
  
      for (OperationDTO op : operations) {
          em.persist(op);
      }
      em.flush();
  </code></pre>
  
  <p>...rest omitted</p>
  
  <p>This exception is being thrown on em.flush():</p>
  
  <pre><code>    org.springframework.integration.transformer.MessageTransformationException: org.springframework.integration.MessageHandlingException: javax.persistence.TransactionRequiredException: no transaction is in progress
  </code></pre>
  
  <p>My integration context contains these elements:</p>
  
  <pre><code>&lt;tx:annotation-driven /&gt;
  
  &lt;bean id="jpaTransactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"&gt;
      &lt;property name="entityManagerFactory" ref="entityManagerFactory" /&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>The AspectJ part:</p>
  
  <pre><code>&lt;tx:advice id="txGatewayJPA" transaction-manager="jpaTransactionManager"&gt;
          &lt;tx:attributes&gt;
              &lt;tx:method name="*HLR*" /&gt;
          &lt;/tx:attributes&gt;
      &lt;/tx:advice&gt;
  </code></pre>
  
  <p></p>
  
  <pre><code>&lt;aop:pointcut id="allServices"
              expression="execution(* com.mypackage.IntegrationService.*(..))" /&gt;
          &lt;aop:advisor advice-ref="txGatewayJPA" pointcut-ref="allServices" /&gt;
      &lt;/aop:config&gt;
  </code></pre>
  
  <p>Hibernate and DB config:</p>
  
  <pre><code>&lt;bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
          &lt;property name="persistenceXmlLocation" value="classpath:META-INF/persistence.xml" /&gt;
          &lt;property name="persistenceUnitName" value="hiperPU" /&gt;
          &lt;property name="dataSource" ref="dataSource" /&gt;
          &lt;property name="jpaVendorAdapter" ref="jpaVendorAdapter" /&gt;
          &lt;property name="jpaDialect" ref="jpaDialect" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="jpaVendorAdapter"
          class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"&gt;
          &lt;property name="database" value="POSTGRESQL" /&gt;
          &lt;property name="databasePlatform" value="org.hibernate.dialect.PostgreSQLDialect" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="jpaDialect" class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" /&gt;
  
  &lt;bean id="dataSource" class="***.ConfigRoutingDatasource"&gt;
          &lt;property name="configName" value="$hiperConfig{DATASOURCE_NAME_DATA}" /&gt;
          &lt;property name="defaultTargetDataSource"&gt;
              &lt;bean class="org.apache.commons.dbcp.BasicDataSource"
                  destroy-method="close"&gt;
                  &lt;property name="driverClassName" value="org.postgresql.Driver" /&gt;
                  &lt;property name="url"
                      value="jdbc:postgresql://XXX" /&gt;
                  &lt;property name="username" value="XXX" /&gt;
                  &lt;property name="password" value="XXX" /&gt;
                  &lt;property name="maxActive" value="50" /&gt;
                  &lt;property name="maxIdle" value="50" /&gt;
                  &lt;property name="maxWait" value="600000" /&gt;
                  &lt;property name="testOnBorrow" value="true" /&gt;
                  &lt;property name="validationQuery" value="select version()" /&gt;
                  &lt;property name="defaultTransactionIsolation"
                      value="#{ T(java.sql.Connection).TRANSACTION_READ_COMMITTED }" /&gt;
              &lt;/bean&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  </code></pre>
  
  <p>It seems to me that I have configured everything what would make my transformer method transactional. Why isn't it working?</p>