赞
踩
表Teacher 别名 A ,表Student 别名 B 分别插入。
//A 表处理 @Override @Transactional public int insert(Teacher record) { log.info("teacher 插入开始...."); return teacherDAO.insert(record); } //B表处理 @Override public int insert(Student record) { log.info("Student 插入处理...."); return studentDAO.insert(record); } //调用方法处理 @Transactional public void testDemo01() throws Exception{ teacherService.insert(getTeacherEntity(2)); studentService.insert(getStudentEntity(2)); }
@Transactional public void testDemo01() throws Exception{ studentService.insert(getStudentEntity(2)); teacherService.insert(getTeacherEntity(2)); } //A @Override @Transactional public int insert(Teacher record) { log.info("teacher 插入开始...."); int ss = teacherDAO.insert(record); int i = 1 / 0; return ss; }
//A
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public int insert(Teacher record) throws Exception{
log.info("teacher 插入开始....");
int ss = teacherDAO.insert(record);
int i = 1 / 0;
return ss;
}
//调用方法 @Transactional public void testDemo01() throws Exception{ studentService.insert(getStudentEntity(2)); teacherService.insert(getTeacherEntity(2)); } //A @Override @Transactional(propagation = Propagation.REQUIRES_NEW) public int insert(Teacher record) throws Exception{ log.info("teacher 插入开始...."); int ss = 0; try{ ss = teacherDAO.insert(record); int i = 1 / 0; }catch (Exception e){ log.error(e.getMessage()); } return ss; }
//调用方法 @Transactional public void testDemo01() throws Exception{ try{ studentService.insert(getStudentEntity(3)); teacherService.insert(getTeacherEntity(3)); }catch (Exception e){ log.error(e.getMessage()); } } //Teacher方法 @Override @Transactional public int insert(Teacher record) throws Exception{ log.info("teacher 插入开始...."); int ss = teacherDAO.insert(record); int i = 1 / 0; return ss; }
@Transactional public void testDemo01() throws Exception{ try{ studentService.insert(getStudentEntity(3)); teacherService.insert(getTeacherEntity(3)); }catch (Exception e){ log.error(e.getMessage()); } } // @Override @Transactional(propagation = Propagation.REQUIRES_NEW) public int insert(Teacher record) throws Exception{ log.info("teacher 插入开始...."); int ss = teacherDAO.insert(record); int i = 1 / 0; return ss; }
@Transactional public void testDemo01() throws Exception{ try{ studentService.insert(getStudentEntity(4)); teacherService.insert(getTeacherEntity(3)); }catch (Exception e){ log.error(e.getMessage()); } } // @Override @Transactional public int insert(Teacher record) throws Exception{ log.info("teacher 插入开始...."); int ss = 0; try { ss = teacherDAO.insert(record); int i = 1 / 0; } catch (Exception e) { log.error(e.getMessage()); } return ss; }
@Transactional public void testDemo01() throws Exception{ try{ studentService.insert(getStudentEntity(5)); teacherService.insert(getTeacherEntity(4)); }catch (Exception e){ log.error(e.getMessage()); } } // @Override @Transactional(propagation = Propagation.REQUIRES_NEW) public int insert(Teacher record) throws Exception{ log.info("teacher 插入开始...."); int ss = 0; try { ss = teacherDAO.insert(record); int i = 1 / 0; } catch (Exception e) { log.error(e.getMessage()); } return ss; }
@Transactional public void testDemo01() throws Exception{ try{ studentService.insert(getStudentEntity(6)); teacherService.insert(getTeacherEntity(5)); }catch (Exception e){ log.error(e.getMessage()); } } // @Override @Transactional public int insert(Teacher record) throws Exception{ log.info("teacher 插入开始...."); int ss = 0; try { ss = teacherDAO.insert(record); int i = 1 / 0; } catch (Exception e) { log.error(e.getMessage()); throw new Exception(e.getMessage()); } return ss; }
@Transactional public void testDemo01() throws Exception{ try{ studentService.insert(getStudentEntity(8)); teacherService.insert(getTeacherEntity(7)); }catch (Exception e){ log.error(e.getMessage()); throw new RuntimeException(e.getCause()); } } //或者指定会滚异常 @Transactional(rollbackFor = {Exception.class}) public void testDemo01() throws Exception{ try{ studentService.insert(getStudentEntity(8)); teacherService.insert(getTeacherEntity(7)); }catch (Exception e){ log.error(e.getMessage()); throw new Exception(e.getCause()); } } // @Override @Transactional public int insert(Teacher record) throws Exception{ log.info("teacher 插入开始...."); int ss = 0; try { ss = teacherDAO.insert(record); int i = 1 / 0; } catch (Exception e) { log.error(e.getMessage()); throw new Exception(e.getMessage()); } return ss; }
@Transactional public void testC() throws Exception{ for (int i = 1; i <4; i++) { try { testService.testDemo01(i); } catch (Exception e) { continue; } } } // @Transactional(propagation = Propagation.REQUIRES_NEW,rollbackFor = {Exception.class}) public void testDemo01(int i) throws Exception{ try{ studentService.insert(getStudentEntity(i)); teacherService.insert(getTeacherEntity(i)); }catch (Exception e){ log.error(e.getMessage()); //手动回滚 TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); throw new Exception(e.getCause()); } } // @Override @Transactional public int insert(Teacher record) throws Exception{ log.info("teacher 插入开始...."); int ss = 0; try { int k= record.getId(); for (int i = 1; i < 3; i++) { if (k==1){ record.setId(1+i); } if (k==2){ record.setId(3+i); } if (k==3){ record.setId(6+i); } ss = teacherDAO.insert(record); if (k==2){ int t = 1 / 0; } } } catch (Exception e) { log.error(e.getMessage()); throw new Exception(e.getMessage()); } return ss; }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。