title: Propagation.REQUIRES_NEW does not create a new transaction in Spring with JPA
body: <p>I have the following scenario. I am using JPA, Spring:</p>
  
  <pre><code>@Autowired
  SampleService service;
  
  @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
  public void PerformLogic(LogicData data) throws SIASFaultMessage
  {
      SampleObject so = createSampleObject();
  
      try{
          .//do some logic to persist things in data
          .
          .
          persistData(data);
          .
          .
          .
  
  
          updateSampleObject(so);     
      }
      catch(Exception){
          updateSampleObject(so);     
          throw new SIASFaultMessage();
      }
  
  }
  
  @Transactional(propagation = Propagation.REQUIRES_NEW)
  public createSampleObject()
  {
      SampleObject so = new SampleObject();
  
      .
      .//initialize so
      .
  
      service.persist(so);        
      return so;
  }
  
  @Transactional(propagation = Propagation.REQUIRES_NEW)
  public updateSampleObject(SampleObject so)
  {               
      service.persist(so);        
      return so;
  }
  </code></pre>
  
  <p>When everything works fine, data is persisted in database without problems. However, when an exception is thrown, I need that the method <strong>updateSampleObject(so)</strong> persist the information in the database. This is not what is happening. If an exception is thrown the method <strong>updateSampleObject</strong> gets rolled back also, which is not what I need. I need that these two methods (<strong><em>createSampleObject</em></strong> and <strong><em>updateSampleObject</em></strong>) get persisted all the time, no matter whether an exception got thrown or not.
  How can I achieve this?</p>
  
  <p>Moreover, if I anotate the methods <strong>createSampleObject</strong> and <strong>updateSampleObject</strong> with:</p>
  
  <pre><code>@Transactional(propagation = Propagation.NEVER)
  </code></pre>
  
  <p>the idea is that an exception is thrown and I get no exception thrown. Where is the problem? Analizing the logs I see this line:</p>
  
  <pre><code>org.springframework.orm.jpa.JpaTransactionManager  ==&gt; Creating new transaction with name [com.test.PerformLogic]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT....
  </code></pre>
  
  <p>which means this transaction is created, but I see no hint of the other transaction.</p>
  
  <p>This is the part of my configuration file for Spring regarding transactions</p>
  
  <pre><code>&lt;bean id="myDataSource"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
      &lt;property name="driverClassName" value="${jdbc.driverClassName}"/&gt;
      &lt;property name="url" value="${jdbc.url}"/&gt;
      &lt;property name="username" value="${jdbc.username}"/&gt;
      &lt;property name="password" value="${jdbc.password}"/&gt;
  &lt;/bean&gt;
  &lt;bean id="entityManagerFactory"
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
      &lt;property name="dataSource" ref="myDataSource"/&gt;
      &lt;property name="packagesToScan" value="cu.jpa"/&gt;
      &lt;property name="persistenceProviderClass" value="org.hibernate.ejb.HibernatePersistence"/&gt;
      &lt;property name="jpaProperties"&gt;
          &lt;props&gt;
              &lt;prop key="hibernate.dialect"&gt;${hibernate.dialect}&lt;/prop&gt;
              &lt;prop key="hibernate.show_sql"&gt;true&lt;/prop&gt;
              &lt;prop key="hibernate.hbm2ddl.auto"&gt;${hdm2ddl.auto}&lt;/prop&gt;
          &lt;/props&gt;
      &lt;/property&gt;
      &lt;property value="/META-INF/jpa-persistence.xml" name="persistenceXmlLocation"/&gt;
      &lt;property name="persistenceUnitName" value="jpaPersistenceUnit"/&gt;
  &lt;/bean&gt;
  
  &lt;bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"&gt;
      &lt;property name="entityManagerFactory" ref="entityManagerFactory"/&gt;
      &lt;property name="nestedTransactionAllowed" value="true" /&gt;
  &lt;/bean&gt;
  
  &lt;tx:annotation-driven transaction-manager="transactionManager"/&gt;
  </code></pre>