title: Container managed Transaction for JPA+Spring+Hibernate in Tomcat
body: <p>I am trying to configure JOTM with JPA,Spring, hibernate and tomcat. I have configured somehow but neither it perform inserts nor updates, in other words, i am unable to perform commits after inserting/updating data. I have following configuration.</p>
  
  <p><strong>%TOMCAT_HOME%/conf/context.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;Context&gt;
      &lt;WatchedResource&gt;WEB-INF/web.xml&lt;/WatchedResource&gt;
      &lt;Resource name="jdbc/myDS" auth="Container" type="javax.sql.XADataSource" factory="org.objectweb.jotm.datasource.DataSourceFactory" driverClassName="com.mysql.jdbc.Driver" username="root" password="mypassword" url="jdbc:mysql://localhost:3306/myDB"/&gt;
      &lt;Resource name="UserTransaction" auth="Container" type="javax.transaction.UserTransaction"/&gt;
      &lt;Transaction factory="org.objectweb.jotm.UserTransactionFactory" jotm.timeout="60"/&gt;
  &lt;/Context&gt;
  </code></pre>
  
  <p><strong>JOTM 2.1.9 libaries extracted in %TOMCAT%/lib</strong></p>
  
  <pre><code>          Jotm-datasource.jar
  ·         Jotm-core.jar
  ·         Xapool.jar
  ·         Log4j.jar
  ·         Commons-loggin-api.jar
  ·         Carol-iiop-delegate.jar
  ·         Carol-interceptors.jar
  ·         Carol.jar
  ·         Ow2-jta-1.1-spec.jar
  ·         Ow2-connector-1.5-spec.jar
  ·         Howl.jar
  </code></pre>
  
  <p><strong>src/main/webapp/META-INF/context.xml</strong></p>
  
  <pre><code>&lt;Context path="/MyJPATest" reloadable="true"&gt;
      &lt;Loader loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader"/&gt;
  &lt;/Context&gt;
  </code></pre>
  
  <p><strong>src/main/webapp/WEB-INF/classes/carol.properties</strong></p>
  
  <pre><code># JNDI (Protocol Invocation)
  
  carol.protocols=jrmp
  
  # Local RMI Invocation
  carol.jvm.rmi.local.call=true
  
  
  # do not use CAROL JNDI wrapper
  carol.start.jndi=false
  
  # do not start a name server
  carol.start.ns=false
  
  # Naming Factory
  carol.jndi.java.naming.factory.url.pkgs=org.apache.naming
  </code></pre>
  
  <p><strong>META-INF/Persistence.xml</strong> </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0"&gt;
      &lt;persistence-unit name="myPersistenceUnit" transaction-type="RESOURCE_LOCAL"&gt;
          &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;
          &lt;jta-data-source&gt;java:comp/env/jdbc/myDS&lt;/jta-data-source&gt;
          &lt;class&gt;com.test.domain.PUser&lt;/class&gt;
          &lt;exclude-unlisted-classes&gt;true&lt;/exclude-unlisted-classes&gt;
          &lt;properties&gt;
              &lt;property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/&gt;
              &lt;property name="hibernate.hbm2ddl.auto" value="update"/&gt;
          &lt;/properties&gt;
      &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p><strong>applicationContext.xml</strong></p>
  
  <pre><code> &lt;bean
          id="entityManagerFactory"
          class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" &gt;
          &lt;property
              name="persistenceUnitName"
              value="myPersistenceUnit" /&gt;
      &lt;/bean&gt;
  
  
      &lt;context:annotation-config /&gt;
  
      &lt;jee:jndi-lookup
          id="jndiUserTransaction"
          jndi-name="java:comp/UserTransaction" /&gt;
  
      &lt;bean
          id="transactionManager"
          class="org.springframework.transaction.jta.JtaTransactionManager" &gt;
  
          &lt;property
              name="userTransaction"
              ref="jndiUserTransaction" /&gt;
      &lt;/bean&gt;
  
  
      &lt;tx:annotation-driven transaction-manager="transactionManager" /&gt;
  
        &lt;jpa:repositories
          base-package="com.test"
          entity-manager-factory-ref="entityManagerFactory" /&gt;
  
  
  
      &lt;bean
          id="hibernate4ExceptionTranslator"
          class="org.springframework.orm.hibernate4.HibernateExceptionTranslator" /&gt;
  </code></pre>
  
  <p><strong>web.xml</strong></p>
  
  <pre><code>&lt;resource-ref&gt;
          &lt;res-ref-name&gt;jdbc/myDS&lt;/res-ref-name&gt;
          &lt;res-type&gt;javax.sql.XADataSource&lt;/res-type&gt;
          &lt;res-auth&gt;Container&lt;/res-auth&gt;
      &lt;/resource-ref&gt;
  </code></pre>
  
  <p><strong>PUserService's method</strong></p>
  
  <pre><code> @Transactional
      public List&lt;PUser&gt; bootstrapUsers( )
      {
  
          List&lt;PUser&gt; users = new ArrayList&lt;PUser&gt;();
  
          try
          {
  
  
              for (int i = 0; i &lt; 5; i++)
              {
  
                  PUser newUser = new PUser();
                  newUser.setName("B_" + i);
                  PUser user = this.pUserRepository.save(newUser);
  
  
                  users.add(user);
  
              }
  
          }
          catch (Exception e)
          {
              this.logger.error(e, e);
  
              return null;
          }
  
          return users;
  
      }
  </code></pre>
  
  <p><strong>src/main/java/com.test.dao.PUserRepository (Spring-data repository)</strong></p>
  
  <pre><code>public interface PUserRepository extends JpaRepository&lt;PUser, Serializable&gt;
  {
  
      PUser findByName(String username);
  }
  </code></pre>
  
  <p>Thanks in advance.</p>