title: TransactionRequiredException Executing an update/delete query
body: <p>Hi I am using hibernate JPA with spring and mongodb and i am running my application on Glassfish-4.0.</p>
  
  <p>My service class is :</p>
  
  <pre><code>@Component
  public class Test {
      @PersistenceContext
      EntityManager em;
      EntityManagerFactory emf;
  
      @Transactional
      public String persist(Details details) {
          details.getUsername();
          details.getPassword();
  
          Query query = em.createNativeQuery("db.details.find(username="+details.getUsername()+"&amp;password="+details.getPassword());
  
          em.getTransaction().begin();
          em.persist(details);
          em.getTransaction().commit();
          em.flush();
          em.clear();
          em.close();
          query.executeUpdate();
          System.out.println("Sucessful!");
          return "persist";        
      }
  }
  </code></pre>
  
  <p>And my spring-context.xml is :</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:p="http://www.springframework.org/schema/p"
      xmlns:mvc="http://www.springframework.org/schema/mvc"
      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-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/context
      http://www.springframework.org/schema/context/spring-context-3.0.xsd
      http://www.springframework.org/schema/mvc
      http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"&gt;
  
      &lt;context:component-scan base-package="com.javapapers.spring.mvc" /&gt;
      &lt;context:annotation-config /&gt;
      &lt;mvc:annotation-driven /&gt;
      &lt;tx:annotation-driven transaction-manager="txManager" /&gt;
      &lt;bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
          &lt;property name="prefix" value="/WEB-INF/view/" /&gt;
          &lt;property name="suffix" value=".jsp" /&gt;
      &lt;/bean&gt;
      &lt;bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean"&gt;
          &lt;property name="persistenceUnitName" value="ogmTest"/&gt;
      &lt;/bean&gt;
      &lt;bean id="txManager" class="org.springframework.transaction.jta.JtaTransactionManager"&gt;
      &lt;/bean&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>I have applied some changes in the code but their is no effect.
  Can anyone please help me to sort out this.
  Thanks in advance.</p>