title: Spring Data JPA and Exists query
body: <p>I'm using Spring Data JPA (with Hibernate as my JPA provider) and want to define an <code>exists</code> method with a HQL query attached:</p>
  
  <pre><code>public interface MyEntityRepository extends CrudRepository&lt;MyEntity, String&gt; {
  
    @Query("select count(e) from MyEntity e where ...")
    public boolean existsIfBlaBla(@Param("id") String id);
  
  }
  </code></pre>
  
  <p>When I run this query, I get a <code>java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Boolean</code>.</p>
  
  <p>How does the HQL query have to look like to make this work? I know I could simply return a Long value and afterwards check in my Java code if <code>count &gt; 0</code>, but that workaround shouldn't be necessary, right? </p>