【发布时间】:2018-12-18 09:22:35
【问题描述】:
我有一个我不明白的问题。 我有这个代码:
@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;
}
这个返回列表为null(被web服务调用并返回{"status":true,"success":true,"result":[null,null],"error":null})
我在很多其他方法中使用相同的代码,唯一的区别是其他使用List<String>或List<Integer>。
我想错误在advancedSearch 方法内,但是如果我在返回之前放了一个System.out.println(missionProfiles),或者如果我用eclipse debug 观察变量它可以工作,否则它返回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),但问题仍然存在。你知道错误在哪里吗?
这是采集的调试
这是missionProfiles
【问题讨论】:
-
Aquisition 是一个实体吗?
-
@AmanChhabra 是的,你需要看吗?
-
您是否尝试过调试 List
收购中的确切内容 -
是的,我发了图,可能问题是对象在使用之前是空的?
-
问题是 Acquisition 中 MissionProfile 的惰性属性,急切地工作。谢谢
标签: java jquery mysql spring jpa