I am quite new to Spring and Java as a whole and I am currently working on an API. I've got this code which accesses MSSQL database, retrieves the results and IS SUPPOSED TO visualize it, but it doesn't work. I mean, if I would only call the procedure and visualize the result set, it would work normally. The problem is that I can't work with the "RatingProcedure" object. When I try get some object's value, it shows me following error:
Hibernate:
{call dis_entity.spdcmpracovnici(?,?,?,?)}
2019-09-02 01:56:01.355 WARN 8720 --- [nio-8050-exec-3] .m.m.a.ExceptionHandlerExceptionResolver : Resolved [java.lang.ClassCastException: class [Ljava.lang.Object; cannot be cast to class com.pproi.dcm.ratingprocedure.RatingProcedure ([Ljava.lang.Object; is in module java.base of loader 'bootstrap'; >com.pproi.dcm.ratingprocedure.RatingProcedure is in unnamed module of loader >org.springframework.boot.devtools.restart.classloader.RestartClassLoader @7193df92)]
The code:
@GetMapping("/replacements/{sourceId}/workers")
public ResponseEntity<List<PossibleReplacementResponseModel>> getReplacements(@PathVariable Integer sourceId,
@RequestParam(required = false) Integer targetWorkerId,
@RequestParam(required = false) Integer targetLineId,
@RequestParam(required = false) String targetWorkplaces) {
List<PossibleReplacementResponseModel> response = new ArrayList<>();
// 400 Bad Request
if ((targetLineId != null && targetWorkerId != null) || (targetWorkplaces != null && targetLineId == null))
return ResponseEntity.badRequest().build();
StoredProcedureQuery ratingProcedure = entityManager.createNamedStoredProcedureQuery("dcmrating");
StoredProcedureQuery storedProcedure = ratingProcedure.setParameter("pk_target_worker", targetWorkerId)
.setParameter("pk_target_sdl", targetLineId).setParameter("pk_target_workplaces", targetWorkplaces)
.setParameter("pk_source_sdl", sourceId);
List<RatingProcedure> ratings = storedProcedure.getResultList();
for(RatingProcedure rating : ratings) {
PossibleReplacementResponseModel responseModel = new PossibleReplacementResponseModel();
Optional<Worker> _worker = workerRepository.findById(rating.getPersonalId());
if(_worker.isPresent()) {
Worker worker = _worker.get();
responseModel.setId(worker.getId());
responseModel.setName(worker.getFullName());
responseModel.setSkills(findWorkersSkills(worker));
responseModel.setPhysicalExamination(findWorkersMedicalExaminationEndDate(worker));
responseModel.setExams(findWorkersExams(worker));
responseModel.setRestrictions(findWorkersRestrictions(worker));
responseModel.setRating(rating.getRating());
}
response.add(responseModel);
}
return ResponseEntity.ok(response);
}
I probably even have an idea about the solution! I probably should customize my Restart Classloader as seen in here, but there my skills end and I have no idea what I should specify in the file.
Any ideas?
Thank you a lot.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…