title: Request processing failed; nested exception is javax.persistence.TransactionRequiredException: No transactional EntityManager available
body: <p>An exception occurs while I'm trying to persist an object.</p>
  
  <pre><code>import org.springframework.transaction.annotation.Transactional;
  
  @Repository("DBRepository")
  @Transactional
  public class DBRepository implements Repository {
  
      @PersistenceContext
      private EntityManager entityManager;
  
      @Override
      public void addElement(Element element) {
          logger.debug("Element {} is going to be added to database", element);
          entityManager.persist(element);
      }
  }
  </code></pre>
  
  <p>persistence.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &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_2_0.xsd"
               version="2.0"&gt;
  
      &lt;persistence-unit name="p_unit" transaction-type="RESOURCE_LOCAL"/&gt;
  
  &lt;/persistence&gt;
  </code></pre>
  
  <p>web.xml</p>
  
  <pre><code>&lt;context-param&gt;
          &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
          &lt;param-value&gt;/WEB-INF/config/jpa-config.xml&lt;/param-value&gt;
  &lt;/context-param&gt;
  
  &lt;listener&gt;
      &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
  &lt;/listener&gt;
  </code></pre>
  
  <p>jpa-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:tx="http://www.springframework.org/schema/tx"
      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-4.0.xsd
          http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd"&gt;
  
      &lt;!-- Using annotation to configure application --&gt;
      &lt;context:annotation-config/&gt;
  
      &lt;context:component-scan base-package="web.tmh"/&gt;
  
      &lt;!-- Tells Spring to use persistence context annotation --&gt;
      &lt;bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/&gt;
  
      &lt;tx:annotation-driven mode="proxy" transaction-manager="transactionManager"/&gt;
  
      &lt;bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"&gt;
          &lt;property name="entityManagerFactory" ref="entityManagerFactory"/&gt;
      &lt;/bean&gt;
  
      &lt;bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
          &lt;property name="persistenceUnitName" value="p_unit"/&gt;
          &lt;property name="dataSource" ref="dataSource"/&gt;
          &lt;property name="jpaVendorAdapter"&gt;
              &lt;bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"&gt;
                  &lt;property name="showSql" value="true"/&gt;
              &lt;/bean&gt;
          &lt;/property&gt;
          &lt;property name="jpaPropertyMap"&gt;
              &lt;map&gt;
                  &lt;entry key="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/&gt;
                  &lt;entry key="hibernate.hbm2ddl.auto" value="update"/&gt;
              &lt;/map&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
          &lt;property name="driverClassName" value="com.mysql.jdbc.Driver"/&gt;
          &lt;!-- autoReconnect=true param allows our application to reconnect to base if connection was lost --&gt;
          &lt;property name="url" value="jdbc:mysql://localhost:3306/TellMeHow?autoReconnect=true"/&gt;
          &lt;property name="username" value="root"/&gt;
          &lt;property name="password" value="root"/&gt;
      &lt;/bean&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>So as you can see I used right Transactional annotation, and have <code>&lt;tx:annotation-driven mode="proxy" transaction-manager="transactionManager"/&gt;</code>in my jpa-config.xml. So I don't really understand why it doesn't want do work</p>