title: Spring - PersistenceContext - No transactional EntityManager available
body: <p>i am using spring with JPA and all my getters are working. I can get object from database but when i try to save something, i get the error "No transactional EntityManager available" and i have the annotations for transactions.</p>
  
  <p>Here is my DAO:     </p>
  
  <pre><code>    @Repository("userDao")
      @Transactional
      //public class UserDaoImpl extends GenericDaoImpl&lt;User, Long&gt; implements IUserDao {
      public class UserDaoImpl implements IUserDao {  
  
          final protected Logger logger = LoggerFactory.getLogger(this.getClass());
  
          public UserDaoImpl() {
          }
  
          @PersistenceContext(unitName = "ovdigitalPU")
          protected EntityManager entityManager;
  
      @Override
          @Transactional(readOnly = false, propagation = Propagation.REQUIRED)
          public void save(User user) throws DuplicatedUserException {
              logger.info("Creating User with username: " + user.getUsername());
              User foundUser = null;
              logger.info("Checking if user already existis...");
              /*foundUser = this.findByUsername(user.getUsername());
  
              if(foundUser != null) {
                  throw new DuplicatedUserException();
              }*/
  
              entityManager.persist(user);
              logger.info("User " + user.getUsername() + " was been saved with success!");
  
          }
  </code></pre>
  
  <p>Here is my root-context.xml</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="UTF-8" standalone="no"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
      xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx"
      xmlns:context="http://www.springframework.org/schema/context"
          xmlns:aop="http://www.springframework.org/schema/aop"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.springframework.org/schema/beans
  http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
  http://www.springframework.org/schema/tx
  http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
  http://www.springframework.org/schema/aop 
  http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
  http://www.springframework.org/schema/mvc 
  http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
  http://www.springframework.org/schema/context 
  http://www.springframework.org/schema/context/spring-context-3.0.xsd"&gt;
  
      &lt;!-- Root Context: defines shared resources visible to all other web components --&gt;
      &lt;context:annotation-config /&gt;
  
      &lt;bean id="viewResolver"
          class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
          &lt;property name="prefix" value="/WEB-INF/views/" /&gt;
          &lt;property name="suffix" value=".jsp" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="ovdigitalDS"
          class="org.apache.commons.dbcp.BasicDataSource"
          p:driverClassName="com.mysql.jdbc.Driver" p:url="jdbc:mysql://localhost/ovdigital"
          p:username="ovdigital" p:password="12345"&gt;
      &lt;/bean&gt;
  
      &lt;bean id="entityManagerFactory"
          class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
          &lt;property name="dataSource" ref="ovdigitalDS" /&gt;
          &lt;property name="jpaVendorAdapter"&gt;
              &lt;bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" /&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;tx:annotation-driven transaction-manager="transactionManager" /&gt;
      &lt;context:spring-configured /&gt;
      &lt;context:annotation-config /&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>And my persistence.xml:</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="UTF-8"?&gt;
      &lt;persistence version="2.0" 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"&gt;
        &lt;persistence-unit name="ovdigitalPU"&gt;
          &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;
          &lt;properties&gt;
            &lt;property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/&gt;
            &lt;property name="hibernate.transaction.auto_close_session" value="false"/&gt;
            &lt;property name="hibernate.show_sql" value="true"/&gt;
            &lt;property name="hibernate.format_sql" value="false"/&gt;
            &lt;property name="hibernate.generate_statistics" value="false"/&gt;
            &lt;property name="hibernate.connection.autocommit" value="true"/&gt;
            &lt;property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/&gt;
          &lt;/properties&gt;
        &lt;/persistence-unit&gt;
      &lt;/persistence&gt;
  </code></pre>
  
  <p>In debugger mode, when the server try to execute this line - <strong>entityManager.persist(user)</strong>; i get this <strong>exception javax.persistence.TransactionRequiredException: No transactional EntityManager available</strong>.</p>
  
  <p>What i can do to solve my problem?</p>