Мой собственный запрос ниже работает нормально oracle sqlplus. Но через собственный запрос JPA, выдавая следующую ошибку:
[ОШИБКА] org.hibernate.util.JDBCExceptionReporter - ORA-00923: ключевое слово FROM не найдено там, где ожидается
Собственный запрос
SELECT sch.school_name, term.term_name, count(material.MATERIAL_ID), sip.SIP_COUNT, ... FROM VA_SCHOOL sch JOIN va_user_school_rel usr1 on sch.school_id=usr1.school_id
JOIN va_user ur ON usr1.USER_ID= ur.USER_ID
JOIN va_user_role_rel urr1 on usr1.user_id=urr1.user_id
JOIN va_role rle ON urr1.role_id= rle.role_id
JOIN va_user_school_rel usr2 on sch.school_id=usr2.school_id
JOIN va_user ur1 ON usr2.USER_ID= ur1.USER_ID
JOIN va_user_role_rel urr2 on usr2.user_id=urr2.user_id
JOIN va_role rle1 ON urr2.role_id= rle1.role_id
JOIN va_term term on term.school_id = usr1.school_id
JOIN va_class course on course.term_id = term.term_id
JOIN va_material material on material.class_id = course.class_id
LEFT JOIN (SELECT VA_CLASS.TERM_ID TERM_ID, COUNT(*) as SIP_COUNT FROM VA_CLASS JOIN VA_MATERIAL ON VA_MATERIAL.CLASS_ID = VA_CLASS.CLASS_ID WHERE VA_CLASS.reference_flag = 'A' AND trunc(VA_MATERIAL.SCHOOL_STATUS) = 0 GROUP BY VA_CLASS.TERM_ID) sip on term.term_id = sip.term_id
WHERE course.reference_flag = 'A' AND rle.role_name='ROLE_1' AND rle1.role_name='ROLE_2'
GROUP BY sch.school_name, term.term_name, sip.SIP_COUNT
ORDER BY sch.school_name, term.term_name
Собственный запрос JPA:
SELECT new MyDTO(sch.school_name, term.term_name, count(material.MATERIAL_ID), sip.SIP_COUNT, ...) FROM VA_SCHOOL sch
JOIN va_user_school_rel usr1 on sch.school_id=usr1.school_id
JOIN va_user ur ON usr1.USER_ID= ur.USER_ID
JOIN va_user_role_rel urr1 on usr1.user_id=urr1.user_id
JOIN va_role rle ON urr1.role_id= rle.role_id
JOIN va_user_school_rel usr2 on sch.school_id=usr2.school_id
JOIN va_user ur1 ON usr2.USER_ID= ur1.USER_ID
JOIN va_user_role_rel urr2 on usr2.user_id=urr2.user_id
JOIN va_role rle1 ON urr2.role_id= rle1.role_id
JOIN va_term term on term.school_id = usr1.school_id
JOIN va_class course on course.term_id = term.term_id
JOIN va_material material on material.class_id = course.class_id
LEFT JOIN (SELECT VA_CLASS.TERM_ID TERM_ID, COUNT(*) as SIP_COUNT FROM VA_CLASS JOIN VA_MATERIAL ON VA_MATERIAL.CLASS_ID = VA_CLASS.CLASS_ID WHERE VA_CLASS.reference_flag = 'A' AND trunc(VA_MATERIAL.SCHOOL_STATUS) = 0 GROUP BY VA_CLASS.TERM_ID) sip on term.term_id = sip.term_id
WHERE course.reference_flag = 'A' AND rle.role_name=:p_roleName AND rle1.role_name=:p_roleName1
GROUP BY sch.school_name, term.term_name, sip.SIP_COUNT
ORDER BY sch.school_name, term.term_name