title: Hibernate: Unable to access TransactionManager or UserTransaction to make physical transaction delegate
body: <p>I was using Servlets, PostgreSQL and Hibernate with EntityManager to build a Web app and everything was working ok until I moved the project to a Maven based project. Now I'm getting this weird exception every time I try to create an EntityManager from an EntityManagerFactory :</p>
  
  <pre><code>org.hibernate.resource.transaction.backend.jta.internal.JtaPlatformInaccessibleException: Unable to access TransactionManager or UserTransaction to make physical transaction delegate
  at org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl.makePhysicalTransactionDelegate(JtaTransactionCoordinatorImpl.java:229)
  at org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl.getTransactionDriverControl(JtaTransactionCoordinatorImpl.java:203)
  at org.hibernate.engine.transaction.internal.TransactionImpl.&lt;init&gt;(TransactionImpl.java:36)
  at org.hibernate.internal.AbstractSessionImpl.getTransaction(AbstractSessionImpl.java:309)
  at org.hibernate.internal.SessionImpl.&lt;init&gt;(SessionImpl.java:277)
  at org.hibernate.internal.SessionFactoryImpl$SessionBuilderImpl.openSession(SessionFactoryImpl.java:1322)
  at org.hibernate.jpa.internal.EntityManagerImpl.internalGetSession(EntityManagerImpl.java:133)
  at org.hibernate.jpa.spi.AbstractEntityManagerImpl.postInit(AbstractEntityManagerImpl.java:174)
  at org.hibernate.jpa.internal.EntityManagerImpl.&lt;init&gt;(EntityManagerImpl.java:83)
  at org.hibernate.jpa.internal.EntityManagerFactoryImpl.internalCreateEntityManager(EntityManagerFactoryImpl.java:311)
  at org.hibernate.jpa.internal.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:278)
  at cl.bicubic.App.getEntityManager(App.java:100)
  at cl.bicubic.dao.DAO.&lt;init&gt;(DAO.java:24)
  at cl.bicubic.dao.UserAtomicDAO.&lt;init&gt;(UserAtomicDAO.java:15)
  at cl.bicubic.Application.init(Application.java:70)
  at javax.servlet.GenericServlet.init(GenericServlet.java:158)
  at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1241)
  at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1154)
  at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:827)
  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:135)
  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
  at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:136)
  at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
  at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
  at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
  at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:526)
  at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
  at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:655)
  at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
  at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1566)
  at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1523)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
  at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
  at java.lang.Thread.run(Thread.java:745)
  </code></pre>
  
  <p>Here is the configuration of Hibernate in the persistance unit:</p>
  
  <pre><code>&lt;properties&gt;
      &lt;property name="hibernate.connection.url" value="jdbc:postgresql://localhost/mydb?charSet=UTF-8"/&gt;
      &lt;property name="hibernate.connection.user" value="dbuser"/&gt;
      &lt;property name="hibernate.connection.password" value="dbpass"/&gt;
      &lt;property name="hibernate.connection.driver_class" value="org.postgresql.Driver"/&gt;
      &lt;property name="hibernate.connection.provider_class" value="org.hibernate.connection.C3P0ConnectionProvider"/&gt;
      &lt;property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL9Dialect"/&gt;
      &lt;property name="hibernate.c3p0.min_size" value="5"/&gt;
      &lt;property name="hibernate.c3p0.max_size" value="20"/&gt;
      &lt;property name="hibernate.c3p0.timeout" value="1800"/&gt;
      &lt;property name="hibernate.c3p0.max_statements" value="50"/&gt;
      &lt;property name="hibernate.connection.charSet" value="UTF-8"/&gt;
      &lt;property name="hibernate.hbm2ddl.auto" value="update"/&gt;
      &lt;property name="hibernate.id.new_generator_mappings" value="true"/&gt;
      &lt;property name="hibernate.show_sql" value="true"/&gt;
      &lt;property name="hibernate.format_sql" value="true"/&gt;
  &lt;/properties&gt;
  </code></pre>
  
  <p>This is how I create the EntityManagerFactory:</p>
  
  <pre><code>public class App {
      ...
      private static EntityManagerFactory entityManagerFactory;
      ...
      public static void setServletContext(ServletContext context) throws IOException {
           ...
           entityManagerFactory = Persistence.createEntityManagerFactory("persistence-unit-name");
           ...
      }
      ...
      public static EntityManager getEntityManager() {
          return entityManagerFactory.createEntityManager(); //Here Throws the Exception
      }
      ...
  }
  </code></pre>
  
  <p>I call this method using a ServletContextListener</p>
  
  <pre><code>@WebListener
  public class ApplicationServletContextListener implements ServletContextListener {
  
      @Override
      public void contextInitialized(ServletContextEvent sce) {
          try {
              App.setServletContext(sce.getServletContext());
          } catch (Exception ex) {
             Logger.getLogger(ApplicationServletContextListener.class.getName()).log(Level.SEVERE, null, ex);
          }
      }
  
      ...
  
  }
  </code></pre>
  
  <p>This is how I try to create the EntityManager</p>
  
  <pre><code>public class DAO {
      ...
      protected EntityManager entityManager;
      ...
      public DAO() {
          entityManager = App.getEntityManager();
          ...
      }
  
      ...
  }
  </code></pre>
  
  <p>I have tried to look for more information about the origin of this JtaPlatformInaccessibleException, but I have found nothing. I'm not sure what's missing.</p>