问题
I needed to change my JPQL query because it turned out that the last element of types ( contains 5 elements ) contains a wildcard so it can itself contain many elements basically. So now I changed the original query to only check if the TestcaseEntity contains 4 types instead of 5 and all the testcases coming out of this query I check now if they have any of the typesVariants ( previous 5 element ) which should deliver the resulting testcases.
So now I wrote a subselect . What I found out now that subselects are not supported in JPQL after FROM.
Is there any way I could write my query to get the testcases (TestcaseEntity) which match my criteria without using a subselect.
Thanks for your help in advance.
//Original query: @Param("types") List types
@Query(value = "SELECT TC FROM TestcaseEntity TC " + "JOIN TC.validTypes VT " + "WHERE VT.typeId IN :types " + "GROUP BY TC.id " + "HAVING COUNT(VT.id) = 5")
//Updated query with subselect + @Param("typesVariant") List //typesVariant
@Query(value = "SELECT TC FROM ( SELECT TC FROM TestcaseEntity TC " + "JOIN TC.validTypes VT " + "WHERE VT.typeId IN :types " + "GROUP BY TC.id " + "HAVING COUNT(VT.id) = 4)"+ " join TC.validTypes VT WHERE VT.typeId IN :typesVariant
GROUP BY TC.id HAVING COUNT(VT.id) > 0")
来源:https://stackoverflow.com/questions/57723211/jpql-query-not-working-after-needed-to-adapt-it