没有外键关联的 关系删除遍历判断

/*
  //删除用户角色关系表无效 数据(careful:just execute once)
  List<User> tempUsers = this.userDao.getUsers();
  List<UserRole> tempUserRoles = this.userRoleManager.getAll();
  for (UserRole duserRole : tempUserRoles) {
     if(duserRole!=null){
      boolean existRelationship = false;//check Whether the user_role's userId  exist in user table. if not,delete
      for (User duser : tempUsers) {
       if(duser!=null){
        if(duserRole.getUser().getId() == duser.getId() ){
         existRelationship = true;
         break;
        }
       }
      }
      if(!existRelationship){//如果该用户ID不存在于用户表,表示无效关系,就删除.
       this.userRoleManager.deleteUserRole(duserRole.getId());
      }
     }
  }
  */

原文地址:https://www.cnblogs.com/jpr1990/p/2497377.html