From 87b143ff58a9dc71752be97bf9aafe7aec436b78 Mon Sep 17 00:00:00 2001 From: Betty Becuwe Date: Tue, 10 Dec 2024 17:14:21 +0100 Subject: [PATCH] fix: test native query --- .../repository/QuestioningRepository.java | 53 ++++++++++++------- 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/platine-management-db/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/repository/QuestioningRepository.java b/platine-management-db/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/repository/QuestioningRepository.java index 50626a0..e6e0d8d 100644 --- a/platine-management-db/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/repository/QuestioningRepository.java +++ b/platine-management-db/src/main/java/fr/insee/survey/datacollectionmanagement/questioning/repository/QuestioningRepository.java @@ -15,25 +15,40 @@ public interface QuestioningRepository extends JpaRepository Questioning findByIdPartitioningAndSurveyUnitIdSu(String idPartitioning, String surveyUnitIdSu); - @Query(""" - SELECT q FROM Questioning q - LEFT JOIN FETCH q.questioningAccreditations acc - LEFT JOIN FETCH q.questioningEvents evt - LEFT JOIN FETCH q.questioningCommunications comm - WHERE q.surveyUnit.idSu = :searchParam - UNION ALL - SELECT q FROM Questioning q - LEFT JOIN FETCH q.questioningAccreditations acc - LEFT JOIN FETCH q.questioningEvents evt - LEFT JOIN FETCH q.questioningCommunications comm - WHERE q.surveyUnit.identificationName = :searchParam - UNION ALL - SELECT q FROM Questioning q - LEFT JOIN FETCH q.questioningAccreditations acc - LEFT JOIN FETCH q.questioningEvents evt - LEFT JOIN FETCH q.questioningCommunications comm - WHERE acc.idContact = :searchParam - """) + @Query(value = """ + (select + q1_0.* + from + questioning q1_0 + where + q1_0.survey_unit_id_su=:searchParam + union + select + q2_0.* + from + questioning q2_0 + join + survey_unit su2_0 + on su2_0.id_su=q2_0.survey_unit_id_su + where + su2_0.identification_name=:searchParam + union + select + q3_0.* + from + questioning q3_0 + left join + questioning_accreditation qa3_0 + on q3_0.id=qa3_0.questioning_id + where + exists(select + 1 + from + questioning_accreditation qa4_0 + where + qa4_0.questioning_id=q3_0.id) + and qa3_0.id_contact=:searchParam) + """, nativeQuery = true) Page findQuestioningByParam(String searchParam,Pageable pageable );