Java Spring data aerospike`findAll(ids)`在结果中返回空值
Java Spring data aerospike`findAll(ids)`在结果中返回空值,java,spring,spring-data,repository-pattern,aerospike,Java,Spring,Spring Data,Repository Pattern,Aerospike,Spring-data-aerospikemethodfindAll(Iterable-ids)为不存在的实体返回带有NULLs的列表 如果某些实体确实存在,而某些实体不存在,则结果将是一个Iterable,同时包含NULLs和现有实体:[entity1,NULL,entity2,NULL] 在处理findAll(Iterable ids)的结果期间,由于NPEs,它不有用 查看源代码后,我在类org.springframework.data.aerospeck.core.aerospeckte
Spring-data-aerospike
methodfindAll(Iterable-ids)
为不存在的实体返回带有NULL
s的列表
如果某些实体确实存在,而某些实体不存在,则结果将是一个Iterable
,同时包含NULL
s和现有实体:[entity1,NULL,entity2,NULL]
在处理findAll(Iterable ids)
的结果期间,由于NPE
s,它不有用
查看源代码后,我在类org.springframework.data.aerospeck.core.aerospecktemplate
中找到了以下方法:
@Override
public <T> List<T> findByIDs(Iterable<Serializable> IDs, Class<T> type){
AerospikePersistentEntity<?> entity = mappingContext.getPersistentEntity(type);
List<Key> kList = new ArrayList<Key>();
IDs.forEach(id -> kList.add(new Key(this.namespace, entity.getSetName(), id.toString())));
Record[] rs = this.client.get(null, kList.toArray(new Key[kList.size()]));
final List<T> tList = new ArrayList<T>();
for(int i=0; i < rs.length; i++)
tList.add(mapToEntity(kList.get(i), type, rs[i])); // <--- mapToEntity here may return NULL (is it a bug or by design?)
return tList;
}
根据设计,这是正常行为吗?一个很好的问题和答案取决于你认为正常的东西。 findByIDs(…)方法最终由Aerospike“get(BatchPolicy策略,Key[]keys)”实现。该方法将返回一个按键顺序排列的记录数组。如果记录不存在,将返回空值
从Aerospike的角度来看,结果是正确的。但从Spring数据的角度来看,它有效吗?Spring如何指示某些记录不可用于请求的ID集?根据设计,这是正常行为吗?一个很好的问题和答案取决于你认为正常的东西。 findByIDs(…)方法最终由Aerospike“get(BatchPolicy策略,Key[]keys)”实现。该方法将返回一个按键顺序排列的记录数组。如果记录不存在,将返回空值 从Aerospike的角度来看,结果是正确的。但从Spring数据的角度来看,它有效吗?Spring如何表示某些记录不可用于请求的ID集?问题出现在最新的快照中 一旦Aerospike团队的smbdy提供了新版本,您就可以使用它了。 到目前为止,您应该过滤空值。这令人沮丧,我同意:)这个问题出现在最新的快照中 一旦Aerospike团队的smbdy提供了新版本,您就可以使用它了。
到目前为止,您应该过滤空值。这很令人沮丧,我同意:)如果rep>=1500,请创建tag
spring data aerospike
?什么是不存在的实体?您正在传递一个不存在的实体的ID吗?根据设计,当您有一个现有实体的列表时,应该使用findAll(id)IDs@CrazySabbath“…根据设计,当您有一个现有实体ID列表时,应该使用findAll(ID)…”,您从哪里得到的?rep>=1500的人可以创建tagspring data aerospike
?什么是不存在的实体?您正在传递一个不存在的实体的ID吗?根据设计,当您有一个现有实体的列表时,应该使用findAll(id)IDs@CrazySabbath“…根据设计,当您有一个现有实体ID的列表时,应该使用findAll(ID)…”,您从哪里得到的?如果指定的ID
s的实体不存在,我想它不应该返回NULL
s。作为一名开发人员,我在处理方面付出了额外的努力,因为在检索结果之后,我们必须添加冗余逻辑以避免NPE。另外,它也令人困惑,因为一堆NULL
s很难解释结果。如果我们把一个代码>存储库< /代码>作为一个隔离接口抽象的数据访问的模式,我们就不应该依赖于数据库特定的东西,我们希望消除它们的影响。我用一个示例更新了我的问题,这个示例是如何处理关系数据库repo.Peter的!彼得!彼得!star67表示有效点,应过滤掉空值。但问题仍然是Spring数据如何表明没有特定ID的记录?如果有一个特定的Sprint数据模式,那么应该使用它。@Helipilot50,Spring数据如何表明没有特定ID的记录?我用SpringDataJPA的类似功能的实现更新了这个问题。正如我们所看到的,模式如下:如果entityManager为ID返回NULL,则将其从结果集合中筛选出来。如果具有指定ID的实体不存在,我认为它不应该返回NULL
s。作为一名开发人员,我在处理方面付出了额外的努力,因为在检索结果之后,我们必须添加冗余逻辑以避免NPE。另外,它也令人困惑,因为一堆NULL
s很难解释结果。如果我们把一个代码>存储库< /代码>作为一个隔离接口抽象的数据访问的模式,我们就不应该依赖于数据库特定的东西,我们希望消除它们的影响。我用一个示例更新了我的问题,这个示例是如何处理关系数据库repo.Peter的!彼得!彼得!star67表示有效点,应过滤掉空值。但问题仍然是Spring数据如何表明没有特定ID的记录?如果有一个特定的Sprint数据模式,那么应该使用它。@Helipilot50,Spring数据如何表明没有特定ID的记录?我用SpringDataJPA的类似功能的实现更新了这个问题。如我们所见,模式如下:如果entityManager为ID返回NULL,则将其从结果集合中筛选出来
public List<T> findAllById(Iterable<ID> ids) {
Assert.notNull(ids, "The given Iterable of Id's must not be null!");
if (!ids.iterator().hasNext()) {
return Collections.emptyList();
}
if (entityInformation.hasCompositeId()) {
List<T> results = new ArrayList<T>();
for (ID id : ids) {
findById(id).ifPresent(results::add); // <--- here is what I meant above - we add only existing entities
}
return results;
}
ByIdsSpecification<T> specification = new ByIdsSpecification<T>(entityInformation);
TypedQuery<T> query = getQuery(specification, Sort.unsorted());
return query.setParameter(specification.parameter, ids).getResultList();
}