title: Spring AOP bring exception after transaction rollback
body: <p>I just play with code and try to understand how the transaction and rollback work in spring (I am using spring-boot and spring-dao). However during my expirements I was faced with exception which cannot be explain by me. 
  So I have a controller</p>
  
  <pre><code>@RestController
  public class OrderController {
  
  @Autowired
  CarSvc carSvc;
  
  @Autowired
  OrderService orderSvc;
  
  @RequestMapping(value="/administrator/order/{id}", produces = "application/json;charset=UTF-8", method = RequestMethod.PUT)
  @ResponseStatus(HttpStatus.OK)
  public Message closeOrder(@PathVariable Long id){
      orderSvc.closeOrder(id);
      return new Massage("test");
  }
  </code></pre>
  
  <p>}</p>
  
  <p>This controller call this service:</p>
  
  <pre><code>@Service
  @Transactional(propagation = Propagation.REQUIRED)
  public class OrderSvc extends AbstractService implements OrderService {
  
  public void closeOrder(Long id) {
      final Order order = getDAO().findOne(id);
      Boolean isUserCanCloseOrder = order.getCarWashId().equals(getCarWashIdForAdmin());
      if(isUserCanCloseOrder){
          final Iterable&lt;Order&gt; all = getDAO().findAll();
          for(Order o : all){
              try {
                  orderRepo.closeOrder(o);
              }catch (Exception e){
                  System.out.printf("error id=" + o.getId() + " , message : " + e.getMessage());
              }
  
          }
  
      }else {
          throw new AuthorizationException("User is not allowed to close order with id = " + id);
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>And this service in try block calls the following repository</p>
  
  <pre><code>@Repository
  public class OrderRepo implements OrderRepository {
  
  @Override
  @Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
  public void closeOrder(Order order) {
      if(order.getClose() != null){
          order.setUpdateVersion(77);
      }else{
          order.setCarWashId(1000L + order.getId());
      }
      final List&lt;OrderedService&gt; services = order.getServices();
      for(OrderedService s: services){
          s.setUpdateVersion(77);
          orderedServiceDAO.save(s);
      }
      orderDAO.save(order);
  }
  </code></pre>
  
  <p>}</p>
  
  <p>The logic is following: for part of <code>order</code> in repository I just set update  version (I need to understand is db was updated ) and for the rest I <code>setCarWashId</code> with not valid value to invoke sql exception and see is rollback work fine (sql exception due to foreign key constraint fails).</p>
  
  <p>At the begging the application works fine and moves through the all orders  and show me <code>System.out.printf</code> from the service with all my bad orders. But then when the loop was finished, the application failed with the following exception:</p>
  
  <pre><code>com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Cannot add or update a child row: a foreign key constraint fails (`pitstop`.`orders`, CONSTRAINT `order_FK1` FOREIGN KEY (`car_wash_id`) REFERENCES `carwash` (`id`))
  at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_121]
  at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_121]
  at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_121]
  at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_121]
  at com.mysql.jdbc.Util.handleNewInstance(Util.java:404) ~[mysql-connector-java-5.1.38.jar:5.1.38]
  at com.mysql.jdbc.Util.getInstance(Util.java:387) ~[mysql-connector-java-5.1.38.jar:5.1.38]
  at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:932) ~[mysql-connector-java-5.1.38.jar:5.1.38]
  at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3878) ~[mysql-connector-java-5.1.38.jar:5.1.38]
  at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3814) ~[mysql-connector-java-5.1.38.jar:5.1.38]
  at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2478) ~[mysql-connector-java-5.1.38.jar:5.1.38]
  at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2625) ~[mysql-connector-java-5.1.38.jar:5.1.38]
  at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2551) ~[mysql-connector-java-5.1.38.jar:5.1.38]
  at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1861) ~[mysql-connector-java-5.1.38.jar:5.1.38]
  at com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2073) ~[mysql-connector-java-5.1.38.jar:5.1.38]
  at com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2009) ~[mysql-connector-java-5.1.38.jar:5.1.38]
  at com.mysql.jdbc.PreparedStatement.executeLargeUpdate(PreparedStatement.java:5094) ~[mysql-connector-java-5.1.38.jar:5.1.38]
  at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1994) ~[mysql-connector-java-5.1.38.jar:5.1.38]
  at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:208) ~[hibernate-core-4.3.11.Final.jar:4.3.11.Final]
  at org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:62) ~[hibernate-core-4.3.11.Final.jar:4.3.11.Final]
  at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:3281) ~[hibernate-core-4.3.11.Final.jar:4.3.11.Final]
  at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:3183) ~[hibernate-core-4.3.11.Final.jar:4.3.11.Final]
  at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:3525) ~[hibernate-core-4.3.11.Final.jar:4.3.11.Final]
  at org.hibernate.action.internal.EntityUpdateAction.execute(EntityUpdateAction.java:159) ~[hibernate-core-4.3.11.Final.jar:4.3.11.Final]
  at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:465) ~[hibernate-core-4.3.11.Final.jar:4.3.11.Final]
  at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:351) ~[hibernate-core-4.3.11.Final.jar:4.3.11.Final]
  at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:350) ~[hibernate-core-4.3.11.Final.jar:4.3.11.Final]
  at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:56) ~[hibernate-core-4.3.11.Final.jar:4.3.11.Final]
  at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1258) ~[hibernate-core-4.3.11.Final.jar:4.3.11.Final]
  at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:425) ~[hibernate-core-4.3.11.Final.jar:4.3.11.Final]
  at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.beforeTransactionCommit(JdbcTransaction.java:101) ~[hibernate-core-4.3.11.Final.jar:4.3.11.Final]
  at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.commit(AbstractTransactionImpl.java:177) ~[hibernate-core-4.3.11.Final.jar:4.3.11.Final]
  at org.hibernate.jpa.internal.TransactionImpl.commit(TransactionImpl.java:77) ~[hibernate-entitymanager-4.3.11.Final.jar:4.3.11.Final]
  at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:517) ~[spring-orm-4.2.6.RELEASE.jar:4.2.6.RELEASE]
  at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:761) ~[spring-tx-4.2.6.RELEASE.jar:4.2.6.RELEASE]
  at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:730) ~[spring-tx-4.2.6.RELEASE.jar:4.2.6.RELEASE]
  at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:485) ~[spring-tx-4.2.6.RELEASE.jar:4.2.6.RELEASE]
  at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:291) ~[spring-tx-4.2.6.RELEASE.jar:4.2.6.RELEASE]
  at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) ~[spring-tx-4.2.6.RELEASE.jar:4.2.6.RELEASE]
  at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.2.6.RELEASE.jar:4.2.6.RELEASE]
  at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208) ~[spring-aop-4.2.6.RELEASE.jar:4.2.6.RELEASE]
  at com.sun.proxy.$Proxy128.closeOrder(Unknown Source) ~[na:na]
  at biz.controllers.rest.administrator.OrderController.closeOrder(OrderController.java:52) ~[classes/:na]
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_121]
  </code></pre>
  
  <p>I understand the exception due to incorrect FK but why it appear? I have catch block for exception. And why in log was mentioned only my controller (<code>biz.controllers.rest.administrator.OrderController.closeOrder</code>) and there is not link to services or repository? </p>
  
  <p>Please explain me, what is going on. 
  Thank you.</p>