title: Spring IllegalStateException: A JTA EntityManager cannot use getTransaction()
body: <p>So after a big refactoring project, I am left with this exception and am unsure as how to correct it. It's dealing with some code that I did not write and I am unfamiliar with how it all works. There are other questions out there dealing with this exception, but none seem to fit my situation.</p>
  
  <p>The class which uses <code>EntityManager</code> is <code>SpecialClaimsCaseRepositoryImpl</code>:</p>
  
  <pre><code>package com.redacted.sch.repository.jpa;
  
  //Imports
  
  @Repository
  public class SpecialClaimsCaseRepositoryImpl extends SimpleJpaRepository&lt;SpecialClaimsCaseDto, SpecialClaimsCaseDto.Id&gt; implements SpecialClaimsCaseRepository{
  
      @PersistenceContext(unitName = "schManager")
      private EntityManager em;
  
            //Some autogenerated methods
  
      public void setEntityManager(EntityManager em) {
          this.em = em;
      }
  
      public EntityManager getEntityManager() {
          return em;
      }
  }
  </code></pre>
  
  <p>Persistence.xml:</p>
  
  <pre><code>&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="schManager"&gt;
          &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;
          &lt;jta-data-source&gt;jdbc/SCH_DS&lt;/jta-data-source&gt;
          &lt;class&gt;com.redacted.sch.domain.model.SpecialClaimsCaseDto&lt;/class&gt;
          &lt;properties&gt;
              &lt;property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.WebSphereExtendedJTATransactionLookup" /&gt;
              &lt;property name="hibernate.cache.region.factory_class" value="net.sf.ehcache.hibernate.SingletonEhCacheRegionFactory" /&gt;
              &lt;property name="hibernate.cache.use_query_cache" value="true" /&gt;
              &lt;property name="hibernate.cache.use_second_level_cache" value="true" /&gt;
              &lt;property name="hibernate.dialect" value="com.bcbsks.hibernate.dialect.DB2Dialect" /&gt;
              &lt;property name="hibernate.format_sql" value="true" /&gt;
              &lt;property name="hibernate.generate_statistics" value="false" /&gt;
              &lt;property name="hibernate.jdbc.use_scrollable_resultset" value="true" /&gt;
          &lt;/properties&gt;
      &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p>sch_model_spring.xml:</p>
  
  <pre><code>&lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:tx="http://www.springframework.org/schema/tx"
      xsi:schemaLocation="http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
          http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"&gt;
  
          &lt;context:component-scan base-package="com.redacted.repository.jpa,
                com.redacted.sch.domain.model,
                com.redacted.sch.repository.jpa,
                com.redacted.sch.service,
                com.redacted.sch.service.impl"/&gt;
  
          &lt;tx:annotation-driven /&gt;
  
          &lt;tx:jta-transaction-manager /&gt;
  
          &lt;!-- Data source used for testing --&gt;
          &lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"&gt;
              &lt;property name="driverClassName" value="com.ibm.db2.jcc.DB2Driver" /&gt;
              &lt;property name="url" value="jdbc:db2:redacted.redacted.com" /&gt;
              &lt;property name="username" value="redacted" /&gt;
              &lt;property name="password" value="redacted" /&gt;
          &lt;/bean&gt;
  
          &lt;bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
                &lt;property name="persistenceUnitName" value="schManager" /&gt;
                &lt;property name="dataSource" ref="dataSource" /&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; 
  &lt;/beans&gt;
  </code></pre>
  
  <p>And here's my project structure:</p>
  
  <p><img src="https://i.stack.imgur.com/l1Rb9.png" alt="enter image description here"></p>
  
  <p>></p>
  
  <p>Here's a portion of the stack trace, with the full trace at this <a href="http://fpaste.org/117413/14051058/" rel="nofollow noreferrer">fpaste</a></p>
  
  <pre><code>Caused by: java.lang.IllegalStateException: A JTA EntityManager cannot use getTransaction()
      at org.hibernate.ejb.AbstractEntityManagerImpl.getTransaction(AbstractEntityManagerImpl.java:985)
      at org.springframework.orm.jpa.DefaultJpaDialect.beginTransaction(DefaultJpaDialect.java:67)
      at org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:380)
      ... 80 more
  </code></pre>
  
  <p>I'm a total noob here, so if any other information is needed just ask and I'll update.</p>
  
  <p>Thanks for all the help!</p>