@Test public void testInsertUser() { User user = new User(); user.setName("wjj"); userService.insert(user); }
public void insert(User user) { DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setName("UserService.insertUser"); def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); def.setTimeout(100); TransactionStatus status = txManager.getTransaction(def); try { userDao.insertUser(user); queryUserById(1); txManager.commit(status); } catch (Exception ex) { txManager.rollback(status); throw new RuntimeException(ex); } }
UserService { public void insert(User user) { DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setName("UserService.insertUser"); def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); def.setTimeout(100); TransactionStatus status = txManager.getTransaction(def); try { userDao.insertUser(user); queryUserById(1); txManager.commit(status); } catch (Exception ex) { txManager.rollback(status); throw new RuntimeException(ex); } } }
UserService { public void insert(User user) { DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setName("UserService.insertUser"); def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); def.setTimeout(100); TransactionStatus status = txManager.getTransaction(def); try { userDao.insertUser(user); queryUserById(1); txManager.commit(status); } catch (Exception ex) { txManager.rollback(status); throw new RuntimeException(ex); } }  }
UserService { public void insert(User user) { DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setName("UserService.insertUser"); def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); def.setTimeout(100); TransactionStatus status = txManager.getTransaction(def); try { userDao.insertUser(user); queryUserById(1); txManager.commit(status); } catch (Exception ex) { txManager.rollback(status); throw new RuntimeException(ex); } }  User getUserById(long id); void insert(User user); @Transactional(propagation = Propagation.REQUIRED) void insert2(User user); @Transactional(propagation = Propagation.REQUIRES_NEW) User queryUserById(long id); List<User> queryByName(String nameLike); }
UserService { public void insert(User user) { DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setName("UserService.insertUser"); def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); def.setTimeout(100); TransactionStatus status = txManager.getTransaction(def); try { userDao.insertUser(user); queryUserById(1); txManager.commit(status); } catch (Exception ex) { txManager.rollback(status); throw new RuntimeException(ex); } }  User getUserById(long id); void insert(User user); @Transactional(propagation = Propagation.REQUIRED) void insert2(User user); @Transactional(propagation = Propagation.REQUIRES_NEW) User queryUserById(long id); List<User> queryByName(String nameLike);  }