title: No transaction in progress exception with Spring 3.1 and JPA 2
body: <p>I have been at this for weeks.  I have tried eclipselink and now just plain JPA.  I keep getting the same issue.  Everytime I try to flush my entity manager I get 'javax.persistence.TransactionRequiredException: no transaction is in progress' exception.  I know its something to do with how I have everything wired but I can't figure it out.</p>
  
  <p>I have tried writing JUnit tests to test, but since I am new to spring that has a entirely different set of issue.</p>
  
  <p>Some things to note: 
  <strong>I am not using a persistence.xml since I am using spring 3.1</strong>
  *<em>App Server: WebSphere 8.5 (Liberty Profile)</em>*</p>
  
  <p>exception</p>
  
  <pre><code>[ERROR   ] SRVE0777E: Exception thrown by application class 'org.springframework.web.servlet.FrameworkServlet.processRequest():894'
  org.springframework.web.util.NestedServletException: Request processing failed; nested exception is javax.persistence.TransactionRequiredException: no transaction is in progress
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:894)
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:595)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1221)
    at [internal classes]
  [ERROR   ] SRVE0315E: An execption occurred: com.ibm.ws.webcontainer.webapp.WebAppErrorReport: org.springframework.web.util.NestedServletException: Request processing failed&amp;#59; nested exception is javax.persistence.TransactionRequiredException: no transaction is in progress
      at com.ibm.ws.webcontainer.webapp.WebAppErrorReport.constructErrorReport(WebAppErrorReport.java:153)
      at com.ibm.ws.webcontainer.webapp.WebAppErrorReport.constructErrorReport(WebAppErrorReport.java:194)
      at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1078)
      at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:4173)
      at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:302)
      at com.ibm.ws.webcontainer.osgi.DynamicVirtualHost.handleRequest(DynamicVirtualHost.java:296)
      at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:1006)
      at com.ibm.ws.webcontainer.osgi.DynamicVirtualHost$1.run(DynamicVirtualHost.java:253)
      at com.ibm.ws.http.dispatcher.internal.channel.HttpDispatcherLink$TaskWrapper.run(HttpDispatcherLink.java:457)
      at com.ibm.ws.threading.internal.Worker.executeWork(Worker.java:398)
      at com.ibm.ws.threading.internal.Worker.run(Worker.java:380)
      at java.lang.Thread.run(Thread.java:662)
  Caused by: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is javax.persistence.TransactionRequiredException: no transaction is in progress
      at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:894)
      at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:595)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
      at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1221)
      at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:757)
      at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:440)
      at com.ibm.ws.webcontainer.filter.WebAppFilterChain.invokeTarget(WebAppFilterChain.java:125)
      at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:92)
      at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
      at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:192)
      at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:89)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:322)
      at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:116)
      at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
      at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
      at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
      at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
      at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
      at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
      at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:182)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
      at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
      at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
      at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:184)
      at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:155)
      at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
      at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
      at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:192)
      at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:89)
      at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:939)
      at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1036)
      ... 9 more
  Caused by: javax.persistence.TransactionRequiredException: no transaction is in progress
      at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:983)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:365)
      at $Proxy120.flush(Unknown Source)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:240)
      at $Proxy120.flush(Unknown Source)
      at com.smartpharm.dao.AbstractGenericDao.save(AbstractGenericDao.java:22)
      at com.smartpharm.account.dao.impl.AccountDaoJpaImpl.createUser(AccountDaoJpaImpl.java:27)
      at com.smartpharm.account.service.impl.AccountServiceImpl.createUser(AccountServiceImpl.java:21)
      at com.smartpharm.account.controller.AccountController.createAccount(AccountController.java:36)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:213)
      at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)
      at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
      at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
      at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
      at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
      at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
      at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
      at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
      ... 49 more
  </code></pre>
  
  <p>pom.xml dependencies</p>
  
  <pre><code>    &lt;properties&gt;
          &lt;org.springframework.version&gt;3.1.1.RELEASE&lt;/org.springframework.version&gt;
      &lt;/properties&gt;
  &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-core&lt;/artifactId&gt;
              &lt;version&gt;${org.springframework.version}&lt;/version&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-beans&lt;/artifactId&gt;
              &lt;version&gt;${org.springframework.version}&lt;/version&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-aop&lt;/artifactId&gt;
              &lt;version&gt;${org.springframework.version}&lt;/version&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-jdbc&lt;/artifactId&gt;
              &lt;version&gt;${org.springframework.version}&lt;/version&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-webmvc&lt;/artifactId&gt;
              &lt;version&gt;${org.springframework.version}&lt;/version&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;commons-dbcp&lt;/groupId&gt;
              &lt;artifactId&gt;commons-dbcp&lt;/artifactId&gt;
              &lt;version&gt;1.3&lt;/version&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;mysql&lt;/groupId&gt;
              &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
              &lt;version&gt;5.1.19&lt;/version&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;commons-pool&lt;/groupId&gt;
              &lt;artifactId&gt;commons-pool&lt;/artifactId&gt;
              &lt;version&gt;1.6&lt;/version&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;commons-codec&lt;/groupId&gt;
              &lt;artifactId&gt;commons-codec&lt;/artifactId&gt;
              &lt;version&gt;1.3&lt;/version&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
              &lt;artifactId&gt;javax.servlet-api&lt;/artifactId&gt;
              &lt;version&gt;3.0.1&lt;/version&gt;
              &lt;scope&gt;compile&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;log4j&lt;/groupId&gt;
              &lt;artifactId&gt;log4j&lt;/artifactId&gt;
              &lt;version&gt;1.2.14&lt;/version&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.lexi.lexidata&lt;/groupId&gt;
              &lt;artifactId&gt;LexiData&lt;/artifactId&gt;
              &lt;version&gt;1.0&lt;/version&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.codehaus.jackson&lt;/groupId&gt;
              &lt;artifactId&gt;jackson-core-asl&lt;/artifactId&gt;
              &lt;version&gt;1.9.6&lt;/version&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.security&lt;/groupId&gt;
              &lt;artifactId&gt;spring-security-core&lt;/artifactId&gt;
              &lt;version&gt;${org.springframework.version}&lt;/version&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.security&lt;/groupId&gt;
              &lt;artifactId&gt;spring-security-web&lt;/artifactId&gt;
              &lt;version&gt;${org.springframework.version}&lt;/version&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.security&lt;/groupId&gt;
              &lt;artifactId&gt;spring-security-taglibs&lt;/artifactId&gt;
              &lt;version&gt;${org.springframework.version}&lt;/version&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.security&lt;/groupId&gt;
              &lt;artifactId&gt;spring-security-config&lt;/artifactId&gt;
              &lt;version&gt;${org.springframework.version}&lt;/version&gt;
              &lt;exclusions&gt;
                  &lt;exclusion&gt;
                      &lt;groupId&gt;org.springframework&lt;/groupId&gt;
                      &lt;artifactId&gt;spring-context&lt;/artifactId&gt;
                  &lt;/exclusion&gt;
                  &lt;exclusion&gt;
                      &lt;groupId&gt;org.springframework&lt;/groupId&gt;
                      &lt;artifactId&gt;spring-core&lt;/artifactId&gt;
                  &lt;/exclusion&gt;
              &lt;/exclusions&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
              &lt;artifactId&gt;jstl&lt;/artifactId&gt;
              &lt;version&gt;1.2&lt;/version&gt;
              &lt;scope&gt;provided&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-tx&lt;/artifactId&gt;
              &lt;version&gt;${org.springframework.version}&lt;/version&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-orm&lt;/artifactId&gt;
              &lt;version&gt;${org.springframework.version}&lt;/version&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate.javax.persistence&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-jpa-2.0-api&lt;/artifactId&gt;
              &lt;version&gt;1.0.1.Final&lt;/version&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.codehaus.jackson&lt;/groupId&gt;
              &lt;artifactId&gt;jackson-core-lgpl&lt;/artifactId&gt;
              &lt;version&gt;1.9.7&lt;/version&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.codehaus.jackson&lt;/groupId&gt;
              &lt;artifactId&gt;jackson-mapper-asl&lt;/artifactId&gt;
              &lt;version&gt;1.9.7&lt;/version&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-entitymanager&lt;/artifactId&gt;
              &lt;version&gt;4.1.4.Final&lt;/version&gt;
              &lt;type&gt;jar&lt;/type&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;cglib&lt;/groupId&gt;
              &lt;artifactId&gt;cglib&lt;/artifactId&gt;
              &lt;version&gt;2.2.2&lt;/version&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;junit&lt;/groupId&gt;
              &lt;artifactId&gt;junit&lt;/artifactId&gt;
              &lt;version&gt;4.10&lt;/version&gt;
              &lt;type&gt;jar&lt;/type&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-test&lt;/artifactId&gt;
              &lt;version&gt;3.1.1.RELEASE&lt;/version&gt;
              &lt;type&gt;jar&lt;/type&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  </code></pre>
  
  <p>app-config.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &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"
      xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd"&gt;
  
  
       &lt;context:annotation-config/&gt;
       &lt;context:component-scan base-package="com.smartpharm"/&gt;   
  
       &lt;import resource="db-config.xml"/&gt;
       &lt;import resource="security-config.xml"/&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>db-config.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jee="http://www.springframework.org/schema/jee"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.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-3.0.xsd"&gt;
  
  
       &lt;jee:jndi-lookup id="lexiDataSource" jndi-name="jdbc/lexiDb" expected-type="javax.sql.DataSource"/&gt; 
       &lt;jee:jndi-lookup id="smartDataSource" jndi-name="jdbc/smartDb" expected-type="javax.sql.DataSource"/&gt;
  
       &lt;bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
          &lt;property name="dataSource" ref="smartDataSource" /&gt;
          &lt;property name="packagesToScan" value="com.smartPharm" /&gt;
          &lt;property name="jpaVendorAdapter"&gt;
             &lt;bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"&gt;
                &lt;property name="showSql" value="true" /&gt;
                &lt;property name="generateDdl" value="true" /&gt;
                &lt;property name="databasePlatform" value="org.hibernate.dialect.MySQL5Dialect" /&gt;
             &lt;/bean&gt;
          &lt;/property&gt;
       &lt;/bean&gt;
  
       &lt;bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager"&gt;
          &lt;property name="entityManagerFactory" ref="entityManagerFactory" /&gt;
       &lt;/bean&gt;
  
       &lt;tx:annotation-driven transaction-manager="txManager" proxy-target-class="false" /&gt;
  
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>AbstractGenericDao</p>
  
  <pre><code>package com.smartpharm.dao;
  
  import javax.persistence.EntityManager;
  import javax.persistence.PersistenceContext;
  
  import org.springframework.transaction.annotation.Transactional;
  
  
  public abstract class AbstractGenericDao&lt;K,PK&gt; implements GenericDao&lt;K,PK&gt; {
  
      @PersistenceContext
      public EntityManager em;
  
      public EntityManager getEntityManager() {
          return em;
      }
  
      @Transactional
      public K save(K toAdd) {
          em.persist(toAdd);
          em.flush();
          return toAdd;
      }
  
      abstract public K find(PK pk);
  
      public void deleteByPrimaryKey(PK pk) {
          em.remove(find(pk));
          em.flush();
      }
  
      public void delete(K toDelete) {
          em.remove(toDelete);
          em.flush();
      }
  
  }
  </code></pre>
  
  <p>AccountDaoJpaImpl
      package com.smartpharm.account.dao.impl;</p>
  
  <pre><code>import org.apache.log4j.Logger;
  import org.springframework.stereotype.Repository;
  import org.springframework.transaction.annotation.Propagation;
  import org.springframework.transaction.annotation.Transactional;
  
  import com.smartpharm.account.dao.AccountDao;
  import com.smartpharm.account.entities.User;
  import com.smartpharm.account.model.CreateUserRequest;
  import com.smartpharm.dao.AbstractGenericDao;
  
  @Repository
  @Transactional
  public class AccountDaoJpaImpl extends AbstractGenericDao&lt;User, Integer&gt; implements AccountDao{
  
      private static Logger log = Logger.getLogger(AccountDaoJpaImpl.class);
  
      @Transactional
      public void createUser(CreateUserRequest createUserRequest){
          log.info("creating User for " + createUserRequest.getEmailAddress());
  
          User user = new User();
          user.setUserName(createUserRequest.getEmailAddress());
          user.setPassword("password");
  
          user = save(user);
  
          log.debug("user " + user.getUserId() + " created");
      }
  
  
      @Override
      public User find(Integer pk) {
          // TODO Auto-generated method stub
          return null;
      }
  }
  </code></pre>
  
  <p>AccountServiceImpl</p>
  
  <pre><code>package com.smartpharm.account.service.impl;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Service;
  import org.springframework.transaction.annotation.Propagation;
  import org.springframework.transaction.annotation.Transactional;
  
  import com.smartpharm.account.dao.AccountDao;
  import com.smartpharm.account.model.CreateUserRequest;
  import com.smartpharm.account.service.AccountService;
  
  
  @Service
  @Transactional
  public class AccountServiceImpl implements AccountService {
  
      @Autowired
      AccountDao accountDao;
  
      @Transactional
      public void createUser(CreateUserRequest request){
          accountDao.createUser(request);
      }
  }
  </code></pre>
  
  <p>AccountController</p>
  
  <pre><code>package com.smartpharm.account.controller;
  
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  import org.apache.log4j.Logger;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Controller;
  import org.springframework.transaction.annotation.Propagation;
  import org.springframework.transaction.annotation.Transactional;
  import org.springframework.web.bind.annotation.RequestBody;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  import org.springframework.web.bind.annotation.ResponseBody;
  
  import com.smartpharm.account.model.CreateUserRequest;
  import com.smartpharm.account.model.CreateUserResponse;
  import com.smartpharm.account.service.AccountService;
  
  @Controller
  public class AccountController {
  
      private static Logger log = Logger.getLogger(AccountController.class);
  
      @Autowired
      AccountService accountService;
  
      public AccountController(){
      }
  
      @RequestMapping(value="/admin/createUser", method=RequestMethod.POST)
      public @ResponseBody CreateUserResponse createAccount(@RequestBody CreateUserRequest createUserRequest, HttpServletRequest request, HttpServletResponse response){
          log.debug(createUserRequest);
  
          accountService.createUser(createUserRequest);
  
          return new CreateUserResponse("userCreated", "no error");
      }
  
  }
  </code></pre>
  
  <p>Also in the log right before it tries to commit at the DB layer I see log that it created then destroyed an EntityManager twice</p>
  
  <pre><code>DEBUG AccountController - CreateUserRequest 
  firstName = test
  middleInit = test
  lastName = tset
  emailAddress = test
  dob = 
  address1 = 
  address2 = 
  city = 
  state = 
  zip = 
  
  
  INFO  AccountDaoJpaImpl - creating User for test
  
  DEBUG SharedEntityManagerCreator$SharedEntityManagerInvocationHandler - Creating new EntityManager for shared EntityManager invocation
  
  DEBUG SessionImpl - Opened session at timestamp: 13426274946
  
  DEBUG EntityManagerFactoryUtils - Closing JPA EntityManager
  
  DEBUG SharedEntityManagerCreator$SharedEntityManagerInvocationHandler - Creating new EntityManager for shared EntityManager invocation
  
  DEBUG SessionImpl - Opened session at timestamp: 13426274950
  
  DEBUG EntityManagerFactoryUtils - Closing JPA EntityManager
  </code></pre>