title: Not active transaciotn: javax.persistence.TransactionRequiredException: Executing an update/delete query
body: <p>why is my transaction not active?
  I have this message:
  "javax.persistence.TransactionRequiredException: Executing an update/delete query"
  I can't find why</p>
  
  <p><strong>aplicationContext:</strong></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:c="http://www.springframework.org/schema/c"
  xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
  xmlns:aop="http://www.springframework.org/schema/aop"
  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-3.2.xsd
      http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd"&gt;
  
  &lt;context:annotation-config /&gt;
  &lt;context:component-scan base-package="com.model.dao" /&gt;
  
  &lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"&gt;
      &lt;property name="driverClassName" value="com.mysql.jdbc.Driver" /&gt;
      &lt;property name="url" value="jdbc:mysql://localhost:3306/punit" /&gt;
      &lt;property name="username" value="root" /&gt;
      &lt;property name="password" value="" /&gt;
      &lt;property name="maxActive" value="10" /&gt;
      &lt;property name="maxIdle" value="10" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="entityManagerFactory"
      class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&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="databasePlatform" value="org.hibernate.dialect.MySQLDialect" /&gt;
          &lt;/bean&gt;
      &lt;/property&gt;
      &lt;property name="jpaPropertyMap"&gt;
          &lt;map&gt;
              &lt;entry key="hibernate.connection.useUnicode" value="true" /&gt;
              &lt;entry key="hibernate.connection.characterEncoding" value="UTF-8" /&gt;
              &lt;entry key="hibernate.jdbc.batch_size" value="30" /&gt;
          &lt;/map&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  
  
  &lt;!-- Transaction Manager --&gt;
  &lt;bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"&gt;
      &lt;property name="entityManagerFactory" ref="entityManagerFactory" /&gt;
  &lt;!--        &lt;property name="dataSource" ref="dataSource" /&gt; --&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p></p>
  
  <p><strong>DAO Impl</strong> </p>
  
  <pre><code>@Component
  public class UserDaoImpl implements UserDao {
  
  @PersistenceContext(unitName="punit")
  private EntityManager em;
  
  protected UserDaoImpl() {
  }
  
      //other ovverrides like find, get
  
  @Override
  @Transactional
  public void deleteUser(String mail, String password) {
      Query q = em.createQuery("DELETE FROM User u WHERE u.mail='"
              + mail + "'AND u.password='" + password
              + "'");
      try{
      q.executeUpdate();
      this.em.flush();
      }catch (PersistenceException pe){
          pe.printStackTrace();
      }
  
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p><strong>persistence.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0"?&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 transaction-type="RESOURCE_LOCAL" name="punit"&gt;
      &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;
      &lt;properties&gt;
          &lt;property name="hibernate.show_sql" value="false" /&gt;
          &lt;property name="hibernate.format_sql" value="true" /&gt;
          &lt;property name="hibernate.hbm2ddl.auto" value="create-drop" /&gt;
          &lt;!-- e.g. validate | update | create | create-drop --&gt;
      &lt;/properties&gt;
  &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p><strong>RemoveUser</strong></p>
  
  <pre><code>public class RemoveUser extends BaseAction{
  
  private static final long serialVersionUID = 1L;
  private String mail;
  private String password;
  
  User user;  
  @Autowired
  UserDaoImpl u;
  
  @Action(value = "removeUser", results = {
          @Result(name="success", location = "pages/loginform.jsp"),
          @Result(name="login", location = "pages/loginform.jsp")})
  public String removeUser(){
      u.deleteUser(mail, password);
              //..logoutAction
      return SUCCESS;
  }
  //..getters and setters...
  }
  </code></pre>
  
  <p><strong>Error</strong></p>
  
  <pre><code>javax.persistence.TransactionRequiredException: Executing an update/delete query
  
  at org.hibernate.ejb.AbstractQueryImpl.executeUpdate(AbstractQueryImpl.java:96)
  at com.model.dao.UserDaoImpl.deleteUser(UserDaoImpl.java:73)
  at com.actions.RemoveUser.removeUser(RemoveUser.java:31)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
  at java.lang.reflect.Method.invoke(Unknown Source)
  at     com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:450)
  at     com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:289)
  </code></pre>