title: Spring @Transactional not committing records
body: <p>I use Spring with Hibernate. I am using following configurations. When I try to save through Spring transaction, the record never commits.</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:context="http://www.springframework.org/schema/context"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:p="http://www.springframework.org/schema/p"
      xsi:schemaLocation="
      http://www.springframework.org/schema/beans 
      http://www.springframework.org/schema/beans/spring-beans.xsd
      http://www.springframework.org/schema/mvc 
      http://www.springframework.org/schema/mvc/spring-mvc.xsd
      http://www.springframework.org/schema/context 
      http://www.springframework.org/schema/context/spring-context.xsd
  
      &lt;context:component-scan base-package="com.wpt.controllers,com.wpt.dao" /&gt;
  
      &lt;mvc:annotation-driven /&gt;
  
      &lt;mvc:default-servlet-handler /&gt;
  
      &lt;bean id="viewResolver"
          class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
          &lt;property name="viewClass"
              value="org.springframework.web.servlet.view.JstlView" /&gt;
          &lt;property name="prefix" value="/WEB-INF/views/" /&gt;
          &lt;property name="suffix" value=".jsp" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="wptDatasource" class="org.apache.commons.dbcp.BasicDataSource"
          destroy-method="close"&gt;
          &lt;property name="driverClassName" value="com.mysql.jdbc.Driver" /&gt;
          &lt;property name="url" value="jdbc:mysql://localhost:3306/wp" /&gt;
          &lt;property name="username" value="user" /&gt;
          &lt;property name="password" value="pass" /&gt;
      &lt;/bean&gt;
      &lt;bean id="hibernate4AnnotatedSessionFactory"
              class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"&gt;
              &lt;property name="dataSource" ref="wptDatasource" /&gt;
              &lt;property name="packagesToScan" value="com.wpt.models" /&gt;
              &lt;property name="hibernateProperties"&gt;
                  &lt;props&gt;
                      &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/prop&gt;
                      &lt;prop key="hibernate.current_session_context_class"&gt;thread&lt;/prop&gt;
                      &lt;prop key="hibernate.show_sql"&gt;false&lt;/prop&gt;
                  &lt;/props&gt;
              &lt;/property&gt;
          &lt;/bean&gt;
  
          &lt;bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"
              p:sessionFactory-ref="hibernate4AnnotatedSessionFactory"&gt;
          &lt;/bean&gt;&lt;/beans&gt;
  </code></pre>
  
  <p>MyControllerClass</p>
  
  <pre><code>@Transactional
  @RequestMapping(...)
  public String saveRecords(@ModelAttribute("orderObj") Order order){
    for(Item item : order.getItems()){
      itemDAO.save(item);
    }
    return "saveSuccess";
  }
  </code></pre>
  
  <p>MyDAOClass</p>
  
  <pre><code>public void save(Item item){
    session = sf.openSession();
    session.save(item);
    session.close();
  }
  </code></pre>
  
  <p>The above @Transactional configuration not committing the record. But if I remove @Transactional from spring controller and use Hibernate transaction as below, the record commits.</p>
  
  <pre><code>public void save(Item item){
    session = sf.openSession();
    Transaction tx = session.beginTransaction();
    session.persist(item);
    tx.commit();
    session.close();
  }
  </code></pre>
  
  <p>This class commits the record.
  I've gone through some forums and it's mentioned that @Transactional will take care of committing records. What mistake I am doing here? Can someone help?</p>
  
  <p>Thanks in advance.</p>