1. @Query(nativeQuery = true,value = "SELECT id FROM app_role as role " +
    2. "WHERE EXISTS (SELECT role_id from app_user_role WHERE is_deleted=0 and user_id=:userId and role_id=role.id) " +
    3. "AND app_id=:appId and is_deleted=0 ")
    4. List<BigInteger> getAllRoleIdsByUserIdAndAppId(Long userId, Long appId);

    原生SQL接ID时,类型是BigInteger

    1. List<BigInteger> roleIds = roleRepository.getAllRoleIdsByUserIdAndAppId(userId, appId);
    2. List<Long> usefulRoleIds=roleIds.stream().mapToLong(BigInteger::longValue)
    3. .boxed().collect(Collectors.toList());

    错误
    现象
    查询时,出现集合数据有重复,但是按照正常的SQL逻辑应该是没有重复数据的
    原因
    jpa的实体指定的主键在查询时,有重复。