gpt4 book ai didi

Java返回空列表而不是对象

转载 作者:行者123 更新时间:2023-11-30 21:41:37 28 4
gpt4 key购买 nike

我有一个我不明白的问题。我有这段代码:

@Override
public List<MissionProfile> populateFilterMissionProfile(List<Integer> fleet, List<Integer> application, List<Integer> vehicle, List<String> dataSet, List<String> shift, List<String> drchannel, List<String> swVersion, String userName){
//If vehicle is null (so not used into filter) than add the allowed vehicles (for the user) to the query to filter the acquisitions by the allowed applications
if (vehicle==null) {
vehicle =fleetHasUserRepository.getAllCarForUser(userName).stream().map(x->x.getIdCar()).collect(Collectors.toList());
}
//Retrieve all the acquisitions for the specific parameters
List<Acquisition> acquisitions = acquisitionRepository.advancedSearch(fleet, application, vehicle, null, dataSet, shift, null, null ,drchannel, swVersion);
List<MissionProfile> missionProfiles = acquisitions.parallelStream().map(x->x.getMissionProfile()).distinct().collect(Collectors.toList());
return missionProfiles;
}

此返回列表为空(它由网络服务调用并返回 {"status":true,"success":true,"result":[null,null],"error":null} )

我在很多其他方法中使用了相同的代码,唯一的区别是其他使用List<String>List<Integer> .我想错误在advancedSearch里面方法,但如果我放一个 System.out.println(missionProfiles)在返回之前,或者如果我用 eclipse 调试观察变量它工作,否则它返回 null (即使我写 missionProfiles.size() 也不起作用,但使用 missionProfiles.get(0).getidMissionProfile() 就可以)
这是数据库代码

@Query("SELECT e "
+ "FROM Acquisition e "
+ " WHERE (COALESCE( :fleet ) is null OR e.car.fleet.fleetName.idFleetName in (:fleet) )"
+ " AND (COALESCE( :application ) is null OR e.car.fleet.idFleet in (:application) )"
+ " AND (COALESCE( :vehicle ) is null OR e.car.idCar in (:vehicle) )"
+ " AND (COALESCE( :mp ) is null OR e.missionProfile.idMissionProfile in (:mp) )"
+ " AND (COALESCE( :dataset ) is null OR e.dataset in (:dataset) )"
+ " AND (COALESCE( :shift ) is null OR e.shift.idShift in (:shift) )"
+ " AND (:dateFrom is null OR e.date >= :dateFrom) "
+ " AND (:dateTo is null OR e.date <= :dateTo) "
+ " AND (COALESCE( :drchannel ) is null OR e.drChannelsConf in (:drchannel) )"
+ " AND (COALESCE( :swVersion ) is null OR e.swVersion.idSwVersion in (:swVersion) )" )
List<Acquisition> advancedSearch( @Param(value = "fleet") List<Integer> fleet,
@Param(value = "application") List<Integer> application,
@Param(value = "vehicle") List<Integer> vehicle,
@Param(value = "mp") List<Integer> mp,
@Param(value = "dataset") List<String> dataSet,
@Param(value = "shift") List<String> shift,
@Param(value = "dateFrom") Date dateFrom,
@Param(value = "dateTo") Date dateTo,
@Param(value = "drchannel") List<String> drchannel,
@Param(value = "swVersion") List<String> swVersionn );

我试过没有流和 Thread.sleep(10000)但问题仍然存在。你知道错误在哪里吗?
这是收购的调试 enter image description here这是使命简介 enter image description here

最佳答案

这是关于 acquisition 实体的Lazy 初始化的问题。我添加了这一行

missionProfiles.forEach(x->Hibernate.initialize(x.getMissionProfile()));

返回之前

关于Java返回空列表而不是对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51266774/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com