title: inserting record in two table within one transaction block in same method
body: <p>I want to insert/update records in two tables within one transaction in same method. </p>
  
  <p>first insert into table1 and if that is successful then update the table2 and then if both  are successful then only commit otherwise dont commit (in both table)</p>
  
  <p>my code is like below:</p>
  
  <pre><code>@Transactional
  public void persistTable1AndTable2() {
      persistTable1(List&lt;Table1Entity&gt;);
      updateTable2(List&lt;Table2Entity&gt;);
  }
  </code></pre>
  
  <p>however when I test the code, and if after persistTable1 line I terminate the process, it still insert the record in first table.
  so it doesnt consider this as block transaction.</p>
  
  <p>I am using mysql.</p>
  
  <p>Just to add: 
  above both table1 and table2 uses separate transactionmanager and entityManagerFactory</p>
  
  <p>Can someone please help</p>
  
  <p>[EDIT]</p>
  
  <p>Code to configure JTA using atomikos API.</p>
  
  <pre><code>//Atomikos related JTA configuration
  @Bean(name="userTransactionServiceImp")
  public UserTransactionServiceImp userTransactionServiceImp()
  {
      Properties properties = new Properties();
      properties.setProperty("com.atomikos.icatch.max_timeout", "600000");
      UserTransactionServiceImp userTransactionServiceImp = new UserTransactionServiceImp(properties);
      return userTransactionServiceImp;
  }
  
  @Bean
  @DependsOn("userTransactionServiceImp")
  public UserTransaction userTransaction()
  {
      UserTransactionImp userTransactionImp = new UserTransactionImp();
      return userTransactionImp;
  }
  
  @Bean
  @DependsOn("userTransactionServiceImp")
  public TransactionManager userTransactionManager()
  {
      UserTransactionManager userTransactionManager = new UserTransactionManager();
      userTransactionManager.setStartupTransactionService(false);
      userTransactionManager.setForceShutdown(false);
      return userTransactionManager;
  }
  
  @Bean
  public PlatformTransactionManager transactionManager()
  {
      return new JtaTransactionManager(userTransaction(), userTransactionManager());
  } 
  </code></pre>
  
  <p>and configure jparepo I am having below config class:</p>
  
  <pre><code>@EnableJpaRepositories(basePackages = {"daemon.repository.entities"}, 
      transactionManagerRef="transactionManager", entityManagerFactoryRef = "eventsEntityMF")
  </code></pre>