I'm having a complex SQL query which I want to execute in my Spring boot application. Following is a part of it's JPQL equivalent:
SELECT j FROM Job j WHERE
( (?6 = 0L) OR
0L IN (SELECT i12.filterFieldId FROM IjpPublishFilterFields i12 WHERE i12.jobId = j.id AND i12.fieldType LIKE 'GRADE') OR
(?6 IN (SELECT node.id FROM Grade node
INNER JOIN Grade parent ON ((node.lft BETWEEN parent.lft AND parent.rgt) AND
parent.id IN (SELECT i1.filterFieldId FROM IjpPublishFilterFields i1 WHERE **j.id** = i1.jobId AND i1.fieldType LIKE 'GRADE'))
WHERE node.organizationId = ?5 AND
node.isActive = true AND
parent.isActive = true )))
Since there are multiple other conditions which require to form 'Where' clause dynamically, I believe @Query
annotation is out of the window.
After a lot of research, still I'm unable to convert this where clause to Specification.
e.g., I can return whole IjpPublishFilterFields
object but can't return just i12.filterFieldId
.
How could I write the where clause using JPA Specification?