title: TransactionRequiredException: No transactional EntityManager available within @Transactional method
body: <p>Having designed Service method including @Transactional method, I faced the problem of "No transactional EntityManager available". 
  Technogoly uses: JPA, Spring, Maven</p>
  
  <p>Exception stackTrace</p>
  
  <pre class="lang-none prettyprint-override"><code>Exception in thread "main" javax.persistence.TransactionRequiredException: No transactional EntityManager available
  at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:273)
  at com.sun.proxy.$Proxy29.merge(Unknown Source)
  at com.restaurant.DAO.OrderDAOImpl.saveOrder(OrderDAOImpl.java:24)
  at com.restaurant.services.DeliveryStaffServiceImpl.changeStatusOfOrder(DeliveryStaffServiceImpl.java:37)
  at com.restaurant.entities.Main.main(Main.java:161)
  </code></pre>
  
  <p>The way I invoke service in main:  </p>
  
  <pre class="lang-java prettyprint-override"><code>DeliveryStaffService del = context.getBean(DeliveryStaffService.class);
      List&lt;Order&gt; listOfOrders = del.getListOfOrders();
  </code></pre>
  
  <p>Trying to figure out the issue tried:</p>
  
  <ol>
  <li>to check versions of Spring in pom.xml;</li>
  <li>to check whether all @transactional methods are public;</li>
  <li>added in beans.xml</li>
  </ol>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/&gt;
  </code></pre>
  
  <p>Moreover, there are a few services with @transactional methods int the same project, which work without any problems.</p>
  
  <p>Here is my persistence.xml:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt;
  &lt;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_2_0.xsd"
  xmlns="http://java.sun.com/xml/ns/persistence"  version="2.0" &gt;
      &lt;persistence-unit name="Restaurant" transaction-type="RESOURCE_LOCAL"&gt;
          &lt;provider&gt;
               org.eclipse.persistence.jpa.PersistenceProvider
          &lt;/provider&gt;
      &lt;properties&gt;
              &lt;property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver" /&gt;
              &lt;property name="javax.persistence.jdbc.url" value="jdbc:derby:..//RestaurantDB1;create=true" /&gt;
              &lt;property name="eclipselink.ddl-generation.output-mode" value="database" /&gt;
                   &lt;property name="eclipselink.weaving" value="static" /&gt;
      &lt;/properties&gt;
      &lt;/persistence-unit&gt;
   &lt;/persistence&gt; 
  </code></pre>
  
  <p>Beans.xml</p>
  
  <pre class="lang-xml prettyprint-override"><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"
      xmlns:tx="http://www.springframework.org/schema/tx"
      xsi:schemaLocation="http://www.springframework.org/schema/beans 
      http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
      http://www.springframework.org/schema/context 
      http://www.springframework.org/schema/context/spring-context-3.2.xsd
      http://www.springframework.org/schema/tx 
      http://www.springframework.org/schema/tx/spring-tx.xsd"&gt;
  
      &lt;context:component-scan base-package="com.restaurant"/&gt;
  
      &lt;bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
          &lt;property name="packagesToScan" value="com.restaurant"/&gt;
          &lt;property name="dataSource" ref="dataSource"/&gt;
          &lt;property name="persistenceUnitName" value="Restaurant"/&gt;
  
          &lt;property name="jpaDialect"&gt; 
          &lt;bean class="org.springframework.orm.jpa.vendor.EclipseLinkJpaDialect"/&gt; 
          &lt;/property&gt; 
  
          &lt;property name="jpaVendorAdapter"&gt; 
              &lt;bean class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter"&gt;
                  &lt;property value="true" name="showSql"/&gt; 
                  &lt;property value="true" name="generateDdl"/&gt;
                  &lt;property name="databasePlatform" value="org.eclipse.persistence.platform.database.DerbyPlatform"/&gt; 
              &lt;/bean&gt; 
          &lt;/property&gt;
  
          &lt;property name="jpaPropertyMap"&gt;
              &lt;map&gt;
                &lt;entry key="eclipselink.weaving" value="false" /&gt;
              &lt;/map&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;
  
      &lt;bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/&gt;
  
      &lt;bean id="dataSource"  class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
          &lt;property name="driverClassName" value="org.apache.derby.jdbc.EmbeddedDriver"/&gt;
          &lt;property name="url" value="jdbc:derby:..//RestaurantDB1;create=true" /&gt; 
      &lt;/bean&gt;
  
      &lt;tx:annotation-driven transaction-manager="transactionManager"/&gt; 
      &lt;tx:annotation-driven proxy-target-class="true"/&gt; 
  &lt;/beans&gt;
  </code></pre>
  
  <p>Service Implementation</p>
  
  <pre><code> @Named
  public class KitchenStaffServiceImpl implements KitchenStaffService {
  
      @Inject
      private ItemDAO itemDAO;
      @Inject
      private OrderDAO orderDAO;
  
      @Override
      public List&lt;Item&gt; viewItems() {
          return itemDAO.viewItems();
      }
  
      @Override
      @Transactional
      public void processItem(Item item) {
          int i=item.getQuantity();
          while(i&gt;0){
              try {
                  Thread.sleep(1000);
                  --i;
              } catch (InterruptedException e) {
                  e.printStackTrace();
              }
          }
          item.setIsCooked(true);
          itemDAO.saveItem(item);
          System.out.println(item.getId());
  
          List&lt;Item&gt; list = item.getOrder().getListOfDishes();
          if(list.stream().allMatch(t -&gt; t.getIsCooked()==true)){
              Order ord = item.getOrder();
              ord.setStatus(StatusOfDelivery.READY_FOR_SHIPMENT);
              orderDAO.saveOrder(ord);
          }
      }
  }
  </code></pre>
  
  <p>DAO Implementation</p>
  
  <pre><code>    @Repository
  public class ItemDAOImpl implements ItemDAO{
  
      @PersistenceContext
      private EntityManager em; 
  
      @Override
      public void saveItem(Item item){
          if(item.getId()==0){
              em.persist(item);
          }else
              em.merge(item);
      }       
  }
  </code></pre>
  
  <p>OrderDAOImpelementation with the method saveOrder(Order order) is the same as in ItemDAO (persist()/merge())</p>
  
  <p>Thanks in advance for any propositions</p>