I am trying to execute a Native Query from a Spring Boot application, but i am getting this error " org.postgresql.util.PSQLException: ERROR: operator does not exist: integer = bytea "
Here are the codes i have written to implement this
@SqlResultSetMapping(
name = "StudentAssessmentValue",
classes = @ConstructorResult(
targetClass = StudentAssessmentDTO.class,
columns = {
@ColumnResult(name = "subject_title", type = String.class),
@ColumnResult(name = "assessment", type = String.class),
}
)
)
@NamedNativeQuery(
name = "getStudentSubjectsAssessment",
query = "SELECT\n" +
" subject.subject_title,\n" +
" j as assessment\n" +
"FROM assessment s\n" +
"JOIN LATERAL jsonb_array_elements(s.assessment) j(elem) ON (j.elem->>'student_id') = :student_id\n" +
"JOIN subject ON subject.id = s.subject_id\n" +
"WHERE s.subject_id IN (:subjects)\n" +
"AND s.academy_year_id = :academy_year_id\n" +
"AND s.term_id = :term_id\n" +
"AND s.section_id = :section_id"
,
resultSetMapping = "StudentAssessmentValue"
)
This is the code in my Respository
@Query(nativeQuery = true, name = "getStudentSubjectsAssessment")
List<StudentAssessmentDTO> getStudentAssessments2(
@Param("student_id") String student_id,
@Param("academy_year_id") Integer academy_year_id,
@Param("section_id") Integer section_id,
@Param("term_id") Integer term_id,
@Param("subjects") Integer[] subjects
);
And i have this in my controller
@GetMapping("/{student_id}/{academy_year_id}/{section_id}/
term_id}")
public List<StudentAssessmentDTO> getStudentAssessment2(
@PathVariable("student_id") String student_id,
@PathVariable("academy_year_id") Integer academy_year_id,
@PathVariable("section_id") Integer section_id,
@PathVariable("term_id") Integer term_id,
@RequestParam(value = "subjects") Integer[] subjects
){
return assessmentService.getStudentAssessments2(student_id, academy_year_id, section_id, term_id, subjects);
}
I have also notice if i remove this part from the query WHERE s.subject_id IN (:subjects) or say i hard code the subjects value like so s.subject_id IN (2,3,4) the code runs successfully. But if the value is coming from the request i then get the error. Here is how the request looks like
localhost:8080/assessment/f3df0bc2-7b4c-49b9-86c9-6e6b01628623/3/4/1?subjects=2,3,4