public class ValidateClaimDataEntity{
...
@OneToMany(mappedBy = "claimDataEntity")
private List<ValidateEventDataEntity> eventDataEntityList;
}
当我做
function(ValidateClaimDataEntity claimDataEntity){
claimDataEntity
.getEventDataEntityList().parallelStream()....
}
我得到空点异常,我调试得到claimDataEntity .getEventDataEntityList() is null 但实际上这个claimDataEntity在db中有相关的事件数据
我在 UT 中这样做:
claimDataEntityRepository.findById(32L).get().getEventDataEntityList().parallelStream().forEach(eventDataEntity -> {
log.info(eventDataEntity.getValidateEventDataId());
});
它记录事件数据
那么,为什么函数 claimData 将 eventList 设为 null ???
------------------v1------------------ ------------
我发现它可能不是流的问题,实际上我在迭代器之前做了一个保存
public ValidateClaimResponse bc(ValidateClaimRequest claimRequest) {
//claim
ValidateClaimDataEntity claimDataEntity = new ValidateClaimDataEntity(claimRequest);
claimDataEntityRepository.save(claimDataEntity);
claimRequest.getEventRequestList()
.forEach(eventRequest -> {
...
//event
ValidateEventDataEntity eventDataEntity = new ValidateEventDataEntity(eventRequest);
eventDataEntity.setValidateClaimDataId(claimDataEntity.getValidateClaimDataId());
eventDataEntityRepository.save(eventDataEntity);
});
System.out.println(claimDataEntity.getEventDataEntityList() == null ? "null" : claimDataEntity.getEventDataEntityList() );
ValidateClaimDataEntity claimDataEntity2 = claimDataEntityRepository.findById(claimDataEntity.getValidateClaimDataId()).get();
System.out.println(claimDataEntity2.getEventDataEntityList() == null ? "null2" : claimDataEntity2.getEventDataEntityList());
我得到了 eventList 的空值