title: TransactionManager from Spring or JNDI? (JBOSS + Spring 3 + Hibernate 4 + JTA)
body: <p>We are using Spring with Hibernate to establish transactions with JTA. The PlatformTransactionManager is the JtaTransactionManager which is wired with the TransactionManager and UserTransaction from narayana.</p>
  
  <pre><code>@Bean
  @Scope("prototype")
  public TransactionManager jbossTransactionManager() {
      return jtaPropertyManager.getJTAEnvironmentBean().getTransactionManager();
  }
  
  @Bean
  @Scope("prototype")
  public UserTransaction jbossUserTransaction() {
      return jtaPropertyManager.getJTAEnvironmentBean().getUserTransaction();
  }
  
  @Bean
  public PlatformTransactionManager transactionManager() {
      return new JtaTransactionManager(jbossUserTransaction(), jbossTransactionManager());
  }
  </code></pre>
  
  <p>I have noted that JtaTransactionManager has the UT and TM I would want. On JBoss 6 EAP, I noted that my DataSource has been used as a WrapperDataSource and that this was related to a different TM. Specifically, it is using the TransactionManagerDelegate. This appears to be the transaction manager provided by JBoss via the JNDI names <code>java:TransactionManager</code> and <code>java:jboss/TransactionManager</code>.  This is preventing my transactions from having transactional boundaries and I leak data on flush. If I remove my configuration and the UT and TM from the container, my transactions transact properly.</p>
  
  <ol>
  <li>What is deciding to use this other TransactionManager? This appears to be the JCA from the container but I do not understand the mechanism for this decision.</li>
  <li>Should I remove my UT and TM and surrender control to the
  container to give these components to my app and rely on the JTA
  platform as is or should I try to gain more control?</li>
  </ol>