title: Transactionrequiredexception, no transaction in progress
body: <p>I've been currently working on a Maven + Spring + Hibernate project. Actually, this is just a test project just to get familiar on how Spring works with Hibernate (+Maven). I've already setup and prepare the necessary dependencies. i.e. the appcontext.xml for Spring, the persistence.xml for Hibernate, the entity and DAO objects for JPA/Persistence/Hibernate.</p>
  
  <p>During debug, persist method throws Transactionrequiredexception, no transaction in progress. I don't know what's causing this</p>
  
  <p>web.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"&gt;
  &lt;listener&gt;
  &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
  &lt;/listener&gt;
  &lt;context-param&gt;
  &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
  &lt;param-value&gt;
          /WEB-INF/applicationContext-datasource.xml
          /WEB-INF/applicationContext.xml          
      &lt;/param-value&gt;
  &lt;/context-param&gt;
  &lt;servlet&gt;
  &lt;servlet-name&gt;appServlet&lt;/servlet-name&gt;
  &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
  &lt;init-param&gt;
    &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
    &lt;param-value&gt;/WEB-INF/applicationContext-servlet.xml&lt;/param-value&gt;
  &lt;/init-param&gt;
  &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
  &lt;/servlet&gt;
  &lt;servlet-mapping&gt;
  &lt;servlet-name&gt;appServlet&lt;/servlet-name&gt;
  &lt;url-pattern&gt;/&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>application-servlet.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:mvc="http://www.springframework.org/schema/mvc"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:context="http://www.springframework.org/schema/context"
  xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
      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.xsd"&gt;
  
  &lt;!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure --&gt;
  
  &lt;!-- Enables the Spring MVC @Controller programming model --&gt;
  &lt;mvc:annotation-driven /&gt;
  
  
  
  &lt;context:component-scan base-package="com.names.home" /&gt;
  
  
  &lt;!-- Default locale set --&gt;
  &lt;bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver"&gt;
      &lt;property name="defaultLocale" value="en"/&gt;
  &lt;/bean&gt;
  
  &lt;!-- Tell Spring to not try to map things in these directories to controllers --&gt;
  &lt;!-- Order must be set to supercede the handler configured by the mvc:annotation-driven annotation --&gt;
  &lt;mvc:resources order="-10" location="/img/" mapping="/img/**" /&gt;
  &lt;mvc:resources order="-10" location="/css/" mapping="/css/**" /&gt;
  &lt;mvc:resources order="-10" location="/js/" mapping="/js/**" /&gt;
  &lt;mvc:resources order="-10" location="/fonts/" mapping="/fonts/**" /&gt;
  &lt;mvc:resources order="-10" location="favicon.ico" mapping="favicon.ico" /&gt;
  &lt;mvc:resources order="-10" location="robots.txt" mapping="robots.txt" /&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>applicationContext-datasource.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;!-- The "webDS" data source is the main data source for names. It is referenced and
       should be configured via JNDI in your particular environment. --&gt;
  
  &lt;jee:jndi-lookup id="datasource" jndi-name="jdbc/web"/&gt;
  
  &lt;bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" /&gt;
  
  &lt;tx:annotation-driven transaction-manager="transactionManager" /&gt;
  
  &lt;context:annotation-config/&gt;
  
  &lt;bean class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" id="entityManagerFactory" &gt;
      &lt;property name="persistenceUnitName" value="wzpu"/&gt;
      &lt;property name="dataSource" ref="datasource" /&gt;
      &lt;property name="jpaDialect"&gt;
          &lt;bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" /&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.dao.annotation.PersistenceExceptionTranslationPostProcessor"/&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>admincontroller.java</p>
  
  <pre><code>package com.names.home;
  
  import javax.annotation.Resource;
  import javax.transaction.Transactional;
  
  import org.springframework.stereotype.Controller;
  import org.springframework.web.bind.annotation.RequestMapping;
  
  
  @Controller
  public class AdminController {
  
  @Resource(name="profiledao")
  protected ProfileDao profiledao;
  
  @RequestMapping(value="/admin/insert")
  @Transactional
  public String insert(){
      Profile pr = new Profile();
      pr.setId(1);
      profiledao.save(pr);
      return "home";
  }
  }
  </code></pre>
  
  <p>ProfileDao.java</p>
  
  <pre><code>package com.names.home;
  
  import javax.persistence.EntityManager;
  import javax.persistence.PersistenceContext;
  
  import org.springframework.stereotype.Repository;
  
  @Repository
  public class ProfileDao {
  
  @PersistenceContext(unitName = "wzpu")
  protected EntityManager em;
  
  public Profile find(){
      return this.em.find(Profile.class, 2);
  }
  
  public void save(Profile profile){
      this.em.persist(profile);
      em.flush();
  }
  }
  </code></pre>
  
  <p>Profile.java</p>
  
  <pre><code>package com.names.home;
  
  import java.io.Serializable;
  
  import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.Id;
  import javax.persistence.Table;
  
  @Entity
  @Table(name = "profile")
  public class Profile implements Serializable{
  
  private static final long serialVersionUID = 1L;
  
  @Id
  @Column(name = "PROFILE_ID",nullable=false,unique=true)
  protected int id;
  
  public Profile() {
      super();
  }
  
  public int getId() {
      return id;
  }
  
  public void setId(int id) {
      this.id = id;
  }
  
  @Override
  public int hashCode() {
      final int prime = 31;
      int result = 1;
      result = prime * result + id;
      return result;
  }
  
  @Override
  public boolean equals(Object obj) {
      if (this == obj)
          return true;
      if (obj == null)
          return false;
      if (getClass() != obj.getClass())
          return false;
      Profile other = (Profile) obj;
      if (id != other.id)
          return false;
      return true;
  }
  
  }
  </code></pre>
  
  <p>Please help me resolving this</p>