public class ValidateClaimDataEntity{
...
@OneToMany(mappedBy = "claimDataEntity")
private List<ValidateEventDataEntity> eventDataEntityList;
}
当我做
时function(ValidateClaimDataEntity claimDataEntity){
claimDataEntity
.getEventDataEntityList().parallelStream()....
}
我有零点例外 .getEventDataentityList((为null但是实际上,这种索赔范围具有DB
中相关的事件数据我以ut的方式做:
claimDataEntityRepository.findById(32L).get().getEventDataEntityList().parallelStream().forEach(eventDataEntity -> {
log.info(eventDataEntity.getValidateEventDataId());
});
它进行日志事件数据
所以,为什么函数索赔符号将eventlist作为null ???
获取eventlist。----------------------------------------------------------------------------------------------------------------------------------------------------------------------
我发现这可能不是流的问题,实际上,我在迭代器之前保存
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的null
@OneToMany
的默认fetchType是懒惰的(一对一的默认fetch type类型,多对一,一对一,在冬眠中一对一(。因此,它没有被取出。使其EAGER
@OneToMany(mappedBy = "claimDataEntity", fetch = FetchType.EAGER)
private List<ValidateEventDataEntity> eventDataEntityList;