title: Using Spring @Transactional propagations in JTA
body: <p>I am trying to implement Client Orchestration Strategy(<a href="http://www.ibm.com/developerworks/java/library/j-ts4/index.html?ca=dat-" rel="nofollow">ibm-client-orchestration</a>) due to our system arhitecture. We use an integration layer which in fact orchestrates some web services. A call to a web services is made in a single unit of work and delegates to a business layer which uses Spring framework. An example would be something like this:</p>
  
  <pre><code>UserTransaction ut = getUserTransaction()
  ut.begin();
  // insert data, will be delegated to some jpa repository
  service1.saveData(data)
  // find data inserted above
  service2.findData(data)
  ut.commit();
  </code></pre>
  
  <p>In the mentioned link, the author suggest to use propagation MANDATORY on save and propagation SUPPORTS on finding, which will try to find data in a transaction log. Somehow, I do not know I am not able to find the inserted data in the find step given the above scenario. Here are some useful information that may help:</p>
  
  <ol>
  <li>we use Websphere 8.5. Our datasouce is comming from Websphere, is configured as XA datasource and it's taken from JNDI.</li>
  <li>Platform transaction manager from Spring is configured as JtaTransactionManager</li>
  <li><p>Entity Manger Factory is taken from a LocalContainerEntityManagerFactoryBean and uses a Hibernate JPA Vendor with the following properties:</p>
  
  <p>jpaProperties.setProperty("hibernate.hbm2ddl.auto",
              environment.getRequiredProperty("entitymanagerfactory.hibernate.hbm2ddl.production"));
      jpaProperties.setProperty("hibernate.connection.autocommit", "false");
      jpaProperties.setProperty("hibernate.transaction.jta.platform", "org.hibernate.service.jta.platform.internal.WebSphereJtaPlatform");
      jpaProperties.setProperty("hibernate.transaction.manager_lookup_class", "org.hibernate.transaction.WebSphereExtendedJTATransactionLookup");</p></li>
  <li><p>I didn't configured any JPA Provider in Websphere, so it should be it's default implementation.</p></li>
  </ol>
  
  <p>I mention that if I use in the delegation DAO layer, the saveAndFlush() method from the jpa repository, I am able to find if, but I would preffer not to use it and use the transaction propagation.</p>
  
  <p>Definition for transactionManager bean:</p>
  
  <pre><code>    @Bean
  public PlatformTransactionManager transactionManager() {
      JtaTransactionManager txManager = new JtaTransactionManager();
      txManager.afterPropertiesSet();
      return txManager;
  }
      @Bean
  public EntityManagerFactory entityManagerFactory() {
      // hibernate vendor
      HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
      vendorAdapter.setDatabase(databaseType());
      vendorAdapter.setGenerateDdl(true);
  
      // compose entityManager
  
      LocalContainerEntityManagerFactoryBean factoryBean = new LocalContainerEntityManagerFactoryBean();
      factoryBean.setJpaVendorAdapter(vendorAdapter);
      factoryBean.setDataSource(datasource());
      factoryBean.setJtaDataSource(datasource());
      // scan packages
      factoryBean.setPackagesToScan(environment.getRequiredProperty("entitymanager.scan.packages"));
  
      // JPA properties
      factoryBean.setJpaProperties(getEntityManagerFactoryJpaProperties());
  
      factoryBean.afterPropertiesSet();
  
      return factoryBean.getObject();
  }
  </code></pre>
  
  <p>Any suggestions are appreciated. 
  Thanks.</p>