title: Could not open JPA EntityManager for transaction. A JTA EntityManager cannot use getTransaction()
body: <p>I am trying to develop Spring+Hibernate+EntityManager+Spring Data+PostgreSQL database on Spring Tools Suite and Pivotal tc Server Developer Edition. My configuration is:
  applicationContext.xml</p>
  
  <pre><code>&lt;context:component-scan base-package="com.me, dk.me" /&gt;
  &lt;jpa:repositories base-package="dk.me.data"
      entity-manager-factory-ref="entityManagerFactory"&gt;
  &lt;/jpa:repositories&gt;
  &lt;!-- tx:jta-transaction-manager /--&gt;
  &lt;bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/&gt;
  &lt;bean id="entityManagerFactory"
      class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
      &lt;property name="persistenceUnitName" value="MyPU"/&gt;
      &lt;property name="jpaVendorAdapter"&gt;
          &lt;bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" /&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;bean id="transactionManager"
      class="org.springframework.orm.jpa.JpaTransactionManager"&gt;
      &lt;property name="entityManagerFactory" ref="entityManagerFactory"/&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>and my persistence.xml is:</p>
  
  <pre><code>&lt;persistence-unit name="MyPU" transaction-type="JTA"&gt;
      &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;
      &lt;properties&gt;
          &lt;property name="hibernate.connection.driver_class" value="org.postgresql.Driver"/&gt;
          &lt;property name="hibernate.connection.username" value="postgres"/&gt;
          &lt;property name="hibernate.connection.password" value="masterkey"/&gt;
          &lt;property name="hibernate.connection.url" value="jdbc:postgresql://localhost:5432/postgres"/&gt;           
          &lt;property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/&gt;
          &lt;property name = "javax.persistence.jdbc.driver" value = "org.postgresql.Driver"/&gt;
          &lt;property name = "javax.persistence.jdbc.url" value = "jdbc:postgresql://localhost:5432/postgres"/&gt;
          &lt;property name = "javax.persistence.jdbc.user" value = "postgres"/&gt;
          &lt;property name = "javax.persistence.jdbc.password" value = "masterkey"/&gt;
          &lt;!-- property name="hibernate.ejb.cfgfile" value="hibernate.cfg.xml"/--&gt;
          &lt;property name="hibernate.transaction.jta.platform" 
          value="org.hibernate.service.jta.platform.internal.JBossStandAloneJtaPlatform" /&gt;
      &lt;/properties&gt;
  &lt;/persistence-unit&gt;     
  </code></pre>
  
  <p>Code is pretty straightforware, there is simple call the the Spring Data repository to read all beans. The error messsage is:</p>
  
  <pre><code>Could not open JPA EntityManager for transaction; nested exception is java.lang.IllegalStateException: A JTA EntityManager cannot use getTransaction()
  </code></pre>
  
  <p>And stack trace:</p>
  
  <pre><code>org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is java.lang.IllegalStateException: A JTA EntityManager cannot use getTransaction()
  at org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:430)
  at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:373)
  at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:420)
  at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:257)
  at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95)
  at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
  at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
  at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
  at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodIntercceptor.invoke(CrudMethodMetadataPostProcessor.java:122)
  at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
  at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
  at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
  at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
  at com.sun.proxy.$Proxy35.findAll(Unknown Source)
  at dk.nmc.imarket.framework.services.FrameworkService.getAll(FrameworkService.java:32)
  at dk.nmc.imarket.web.framework.FrameworkListFrame.getAll(FrameworkListFrame.java:37)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
  at java.lang.reflect.Method.invoke(Unknown Source)
  at javax.el.BeanELResolver.getValue(BeanELResolver.java:97)
  at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
  at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
  at org.apache.el.parser.AstValue.getValue(AstValue.java:167)
  at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:187)
  at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
  at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
  at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:182)
  at javax.faces.component.UIData.getValue(UIData.java:730)
  at org.primefaces.component.datatable.DataTable.getValue(DataTable.java:729)
  at org.primefaces.component.api.UIData.getDataModel(UIData.java:575)
  at javax.faces.component.UIData.getRowCount(UIData.java:355)
  at org.primefaces.component.datatable.DataTableRenderer.encodeTbody(DataTableRenderer.java:579)
  at org.primefaces.component.datatable.DataTableRenderer.encodeRegularTable(DataTableRenderer.java:220)
  at org.primefaces.component.datatable.DataTableRenderer.encodeMarkup(DataTableRenderer.java:192)
  at org.primefaces.component.datatable.DataTableRenderer.encodeEnd(DataTableRenderer.java:74)
  at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
  at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1786)
  at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782)
  at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782)
  at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:424)
  at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:124)
  at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:288)
  at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:288)
  at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:288)
  at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
  at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
  at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
  at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
  at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
  at com.nmc.nxapps.web.filters.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:33)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
  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.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:146)
  at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:277)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
  at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
  at java.lang.Thread.run(Unknown Source)
  Caused by: java.lang.IllegalStateException: A JTA EntityManager cannot use getTransaction()
  at org.hibernate.jpa.spi.AbstractEntityManagerImpl.getTransaction(AbstractEntityManagerImpl.java:1368)
  at org.springframework.orm.jpa.DefaultJpaDialect.beginTransaction(DefaultJpaDialect.java:67)
  at org.springframework.orm.jpa.vendor.HibernateJpaDialect.beginTransaction(HibernateJpaDialect.java:110)
  at org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:380)
  ... 72 more
  </code></pre>
  
  <p>The question is - does my configuration make some sende, what should be corrected. I am aware that there are a lot of design choices (e.g. local vs. distributed transactions, use of data sources and so on), but I would like to arrive at the configuration that is the most similar to the current one, to proceed smoothly with the development itself. I am using the most recent compatible (4.x) versionas of Spring and Hibernate, there are no version conflicts in pom.xml and there are no mavan package or deploy time exceptions. The exception is raised when the first request is made at runtime.</p>
  
  <p>Thanks for any suggestions in advance.</p>