@Query(nativeQuery = true,value = "SELECT id FROM app_role as role " +"WHERE EXISTS (SELECT role_id from app_user_role WHERE is_deleted=0 and user_id=:userId and role_id=role.id) " +"AND app_id=:appId and is_deleted=0 ")List<BigInteger> getAllRoleIdsByUserIdAndAppId(Long userId, Long appId);
原生SQL接ID时,类型是BigInteger
List<BigInteger> roleIds = roleRepository.getAllRoleIdsByUserIdAndAppId(userId, appId);List<Long> usefulRoleIds=roleIds.stream().mapToLong(BigInteger::longValue).boxed().collect(Collectors.toList());
错误
现象
查询时,出现集合数据有重复,但是按照正常的SQL逻辑应该是没有重复数据的
原因
jpa的实体指定的主键在查询时,有重复。
