title: Spring Propagation requires_new not working
body: <p>I have the following scenario where I had 2 service layers taking care of inserting data in to emp table and dept table.</p>
  
  <p>I have written query to fail insert on dept table i.e deptno cannot accept deptno with length > 2, hence it will not inserted into db due to DataIntegrity violation. I don't want my previous transaction to be dependent on this transaction. So used REQUIRES_NEW propagation level.</p>
  
  <p>Here is my code.</p>
  
  <pre><code>@Component
  public class EmployeeServiceImpl implements EmployeeService {
  
      @Autowired
      private EmployeeDao employeeDao;
  
      @Autowired
      private DeptService deptService;
  
      @Transactional(propagation = Propagation.REQUIRED)
      public boolean createEmployee() {
          employeeDao.insertEmployee();
          deptService.createDept();
          return false;
      }
  }
  
  @Component
  public class DeptServiceImpl implements DeptService {
  
      @Autowired
      private DeptDao deptDao;
  
      @Transactional(propagation = Propagation.REQUIRES_NEW)
      public boolean createDept() {
          deptDao.insertDepartment();
          return false;
      }
  }
  </code></pre>
  
  <p>Below is Dao layer</p>
  
  <pre><code>@Component
  public class EmployeeDaoImpl implements EmployeeDao {
  
      private String empInsert = "INSERT INTO emp VALUES ('1000','Ravi','CLERK','7782','1990-01-01','1235.00',NULL,'50');";
  
      @Autowired
      private JdbcTemplate jdbcTemplate;
  
      public boolean insertEmployee() {
  
          int n = jdbcTemplate.update(empInsert);
          return true;
      }
  }
  
  @Component
  public class DeptDaoImpl implements DeptDao {
  
      private String deptInsert = "INSERT INTO dept VALUES ('500','MATERIAL','ALASKA');";
  
      @Autowired
      private JdbcTemplate jdbcTemplate;
  
      public boolean insertDepartment(){
          jdbcTemplate.update(deptInsert);
          return true;
      }
  
  }
  </code></pre>
  
  <p>The following code is called from main class</p>
  
  <pre><code>public static void main(String[] args) {
          ApplicationContext context = new ClassPathXmlApplicationContext("txrequirednew.xml");
          EmployeeService es = (EmployeeService) context.getBean("employeeServiceImpl");
          es.createEmployee();
      }
  </code></pre>
  
  <p>Below is my application context:</p>
  
  <pre><code>   &lt;beans&gt;
  
       &lt;context:annotation-config/&gt;
          &lt;context:component-scan base-package="txrequirednew"&gt;
      &lt;/context:component-scan&gt;
  
          &lt;bean id="dataSource" class="org.springframework.jdbc.datasource.SingleConnectionDataSource"&gt;
              &lt;property name="driverClassName" value="com.mysql.jdbc.Driver"&gt;&lt;/property&gt;
              &lt;property name="url" value="jdbc:mysql://localhost:3306/tejadb"&gt;&lt;/property&gt;
              &lt;property name="username" value="root"/&gt;
              &lt;property name="password" value="sai"/&gt;
          &lt;/bean&gt;
  
          &lt;!-- Dao Configurations--&gt;
          &lt;bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"&gt;
              &lt;property name="dataSource" ref="dataSource"/&gt;
          &lt;/bean&gt;
  
          &lt;tx:annotation-driven transaction-manager="transactionManager" /&gt;
  
          &lt;bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"&gt;
              &lt;property name="dataSource" ref="dataSource" /&gt;
          &lt;/bean&gt;
  
      &lt;/beans&gt;
  </code></pre>
  
  <p>When I try to execute , both the transactions are roll back. But I don't want my first transaction to be rollback.</p>
  
  <p>What is that I am missing here and that's causing rollback on both transactions?
  How can I fix this.</p>