title: Transaction "REQUIRED" propagation in Spring
body: <p>I'm new to Spring and I'm not able to make the transaction propagation in "REQUIRED" mode.</p>
  
  <p>Here is an example:</p>
  
  <pre><code>@Controller
  public class ExampleController
  {
      @Autowired
      Foo foo;
  
      @Autowired
      Bar bar;
  
      @RequestMapping(value = "/example")
      public String submitForm(Model model) throws Exception
      {
          User user = new User("Joe", "Bloggs");
          user = foo.save(user);
          bar.simpleMethod(user);
          return "success";
      }
  }
  </code></pre>
  
  <hr>
  
  <pre><code>@Repository
  public class Foo
  {
      // A JPA repository
      private EntityManager em;
  
      @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
      public User save(User user)
      {
          return this.em.merge(user);
      }
  
      @PersistenceContext
      void setEntityManager(EntityManager entityManager)
      {
          this.em = entityManager;
      }
  }
  </code></pre>
  
  <hr>
  
  <pre><code>public class Bar
  {
      @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
      public void simpleMethod(User user)
      {
          // Do something...
      }
  }
  </code></pre>
  
  <p>The applicationContext.xml (important bits):</p>
  
  <pre><code>&lt;beans xmlns="http://www.springframework.org/schema/beans"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
         xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-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/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd"&gt;
      &lt;context:property-placeholder location="/WEB-INF/jdbc.properties" /&gt;
  
      &lt;bean id="dataSource" class="org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy"&gt;
          &lt;constructor-arg&gt;
              &lt;bean class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
                  &lt;property name="driverClassName" value="${db.driverClassName}" /&gt;
                  &lt;property name="url" value="${db.url}" /&gt;
                  &lt;property name="username" value="${db.username}" /&gt;
                  &lt;property name="password" value="${db.password}" /&gt;
              &lt;/bean&gt;
          &lt;/constructor-arg&gt;
      &lt;/bean&gt;
  
      &lt;bean id="jpaAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"&gt;
          &lt;property name="databasePlatform" value="org.hibernate.dialect.MySQL5Dialect" /&gt;
          &lt;property name="showSql" value="${db.showSql}" /&gt;
          &lt;property name="generateDdl" value="${db.generateDdl}" /&gt;
      &lt;/bean&gt;
  
      &lt;!-- enabling annotation driven configuration /--&gt;
      &lt;context:annotation-config /&gt;
      &lt;context:component-scan base-package="my.package" /&gt;
  
      &lt;!-- Instructs the container to look for beans with @Transactional and decorate them --&gt;
      &lt;tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" /&gt;
  
      &lt;!-- FactoryBean that creates the EntityManagerFactory  --&gt;
      &lt;bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
          &lt;property name="jpaVendorAdapter" ref="jpaAdapter" /&gt;
          &lt;property name="jpaProperties"&gt;
              &lt;props&gt;
                  &lt;prop key="hibernate.show_sql"&gt;true&lt;/prop&gt;
                  &lt;prop key="hibernate.format_sql"&gt;true&lt;/prop&gt;
                  &lt;prop key="hibernate.hbm2ddl.auto"&gt;update&lt;/prop&gt;
              &lt;/props&gt;
          &lt;/property&gt;
          &lt;property name="dataSource" ref="dataSource" /&gt;
      &lt;/bean&gt;
  
      &lt;!-- A transaction manager for working with JPA EntityManagerFactories --&gt;
      &lt;bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"&gt;
          &lt;property name="entityManagerFactory" ref="entityManagerFactory" /&gt;
      &lt;/bean&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>If an exception occours in <code>bar.simpleMethod()</code>, <code>foo.save(...)</code> is not rolled back (or maybe it is, but the database is certainly not). Does anyone know why?</p>