JPQL query not working after needed to adapt it

删除回忆录丶 提交于 2019-12-25 01:49:34

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!