title: Spring @Transactional - mix JPA and JDBCTemplate - no transaction is in progress
body: <p>We have this JPA/Spring setup and we have looked at many other threads about the same error. It appears that we have followed the right approach. But when we test this in WebSphere we see the dreaded</p>
  
  <pre><code>javax.persistence.TransactionRequiredException: no transaction is in progress
  </code></pre>
  
  <p>We know that we can mix JPA and JDBCTemplate queries in a Spring transaction. But we need an Spring/JPA expert to look at our configuration.</p>
  
  <p><b>Code</b></p>
  
  <pre><code>@PersistenceContext(unitName="pu1")
  private EntityManager entityManager;
  
  @Transactional("jpaTransactionManager")
  public DeviceVO updatedDevStatus( Test test) { 
       entityManager.persist(test)
       entityManager.flush();
  }
  </code></pre>
  
  <p><b>JPA configuration </b>
      
          
          
          
          
      </p>
  
  <pre><code>&lt;bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"&gt;
      &lt;property name="dataSource" ref="jndiDataSource"&gt;&lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;!-- JPA --&gt;
  
  &lt;bean id="jpaTransactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"&gt;  
      &lt;property name="entityManagerFactory" ref="entityManagerFactory"&gt;&lt;/property&gt;
  &lt;/bean&gt; 
  
  &lt;bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
      &lt;property name="persistenceXmlLocation" value="classpath:config/persistence.xml" /&gt;
      &lt;property name="persistenceUnitName" value="pu1" /&gt;        
      &lt;property name="dataSource" ref="jndiDataSource" /&gt;
      &lt;property name="packagesToScan" value="com.test.*" /&gt;
      &lt;property name="jpaVendorAdapter"&gt;
          &lt;bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"&gt;
              &lt;property name="showSql" value="true" /&gt;
              &lt;!-- &lt;property name="databasePlatform" value="org.hibernate.dialect.MySQLDialect" /&gt; --&gt;
              &lt;property name="databasePlatform" value="org.hibernate.dialect.DB2Dialect" /&gt;
          &lt;/bean&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;!-- Enable the configuration of transactional behavior based on annotations --&gt;
  &lt;tx:annotation-driven transaction-manager="jpaTransactionManager"/&gt;
  </code></pre>
  
  <p><b>Trace</b></p>
  
  <pre><code>[14/08/15 14:48:53:689 BST] 0000002b SystemOut     O DEBUG [WebContainer :  0] DataExceptions.&lt;init&gt;(25) | javax.persistence.TransactionRequiredException: no transaction is in progress
  [14/08/15 14:48:53:672 BST] 0000002b SystemErr     R javax.persistence.TransactionRequiredException: no transaction is in progress
  [14/08/15 14:48:53:673 BST] 0000002b SystemErr     R    at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:993)
  [14/08/15 14:48:53:673 BST] 0000002b SystemErr     R    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  [14/08/15 14:48:53:673 BST] 0000002b SystemErr     R    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
  [14/08/15 14:48:53:674 BST] 0000002b SystemErr     R    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
  [14/08/15 14:48:53:674 BST] 0000002b SystemErr     R    at java.lang.reflect.Method.invoke(Method.java:611)
  [14/08/15 14:48:53:674 BST] 0000002b SystemErr     R    at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:342)
  [14/08/15 14:48:53:674 BST] 0000002b SystemErr     R    at $Proxy800.flush(Unknown Source)
  [14/08/15 14:48:53:675 BST] 0000002b SystemErr     R    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  [14/08/15 14:48:53:675 BST] 0000002b SystemErr     R    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
  [14/08/15 14:48:53:675 BST] 0000002b SystemErr     R    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
  [14/08/15 14:48:53:675 BST] 0000002b SystemErr     R    at java.lang.reflect.Method.invoke(Method.java:611)
  [14/08/15 14:48:53:676 BST] 0000002b SystemErr     R    at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:262)
  [14/08/15 14:48:53:676 BST] 0000002b SystemErr     R    at $Proxy800.flush(Unknown Source)
  [14/08/15 14:48:53:676 BST] 0000002b SystemErr     R    at com.hrg.storecard.portal.service.dao.impl.DeviceDaoImpl.updatedDevStatus(DeviceDaoImpl.java:206)
  [14/08/15 14:48:53:676 BST] 0000002b SystemErr     R    at com.hrg.storecard.portal.service.business.impl.DeviceServiceImpl.updateDeviceStatus(DeviceServiceImpl.java:94)
  [14/08/15 14:48:53:676 BST] 0000002b SystemErr     R    at com.hrg.storecard.portal.controller.ManageDeviceController.updateDeviceStatus(ManageDeviceController.java:133)
  [14/08/15 14:48:53:677 BST] 0000002b SystemErr     R    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  [14/08/15 14:48:53:677 BST] 0000002b SystemErr     R    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
  [14/08/15 14:48:53:677 BST] 0000002b SystemErr     R    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
  [14/08/15 14:48:53:677 BST] 0000002b SystemErr     R    at java.lang.reflect.Method.invoke(Method.java:611)
  [14/08/15 14:48:53:677 BST] 0000002b SystemErr     R    at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)
  [14/08/15 14:48:53:678 BST] 0000002b SystemErr     R    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
  [14/08/15 14:48:53:678 BST] 0000002b SystemErr     R    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
  [14/08/15 14:48:53:678 BST] 0000002b SystemErr     R    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:749)
  [14/08/15 14:48:53:679 BST] 0000002b SystemErr     R    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:689)
  [14/08/15 14:48:53:679 BST] 0000002b SystemErr     R    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
  [14/08/15 14:48:53:680 BST] 0000002b SystemErr     R    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:938)
  [14/08/15 14:48:53:680 BST] 0000002b SystemErr     R    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)
  [14/08/15 14:48:53:680 BST] 0000002b SystemErr     R    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
  [14/08/15 14:48:53:680 BST] 0000002b SystemErr     R    at org.springframework.web.servlet.FrameworkServlet.doPut(FrameworkServlet.java:874)
  </code></pre>