Is Select EXISTS() possible in JPQL?
This answer is obsolete. Please refer to correct answer from Rene Link
No, it is not possible.
Refer to the JPQL BNF documentation from oracle.
simple_cond_expression ::= comparison_expression | between_expression | like_expression | in_expression | null_comparison_expression | empty_collection_comparison_expression | collection_member_expression | exists_expression
exists_expression ::= [NOT] EXISTS(subquery)
Spring Data JPA: Check Exists Entity ID with @Query Annotation
Assuming your Territory entity has a field called "id".
Change your query to:
@Query("SELECT COUNT(e)>0 FROM PlanDetail e WHERE e.territory.id=?1")
JPQL subquery with exists
You need to use r2
instead of r
outside the subquery
@Query("SELECT r2 FROM Restaurant r2
WHERE EXISTS
(SELECT r, COUNT(r) FROM
Restaurant r INNER JOIN r.foods rf WHERE rf IN :foods AND r2=r GROUP BY r
HAVING COUNT(r)=:size)
AND r2.name LIKE '%:name%' AND r2.neighbourhood IN
:neighbourhoods AND r.maxCapacity >= :maxCapacity")
Related Topics
Java Socket Api: How to Tell If a Connection Has Been Closed
Null Pointer on an Autowired Bean Which Is Not Mocked by Mockito
Spring Rest - Create Zip File and Send It to the Client
How to Display Auto-Configuration Report When Running a Spring Boot Application
How to Get the Average of a 2D Array
Java.Lang.Noclassdeffounderror: Lorg/Apache/Logging/Log4J/Logger; But the Artifact Exists
Correct Way to Focus an Element in Selenium Webdriver Using Java
Http 415 Unsupported Media Type Error With Json
Jpa- Joining Two Tables in Non-Entity Class
In Java, How to Determine If a Char Array Contains a Particular Character
Remove Trailing Comma from Comma-Separated String
Better Way to Detect If a String Contains Multiple Words
How to Parse Json Boolean Value
Java.Lang.Illegalargumentexception: Not a Managed Type: Class
How to Do a Limit Query in Jpql or Hql
Dynamically Change Application.Properties Values in Spring Boot