title: How to return boolean result from SQL count via JPQL
body: <p>I have a simple problem with sql query. I need to get true or false, I have tried multiple methods, but without good result. This query returns 0 because I have zero records in database. Perhaps the condition should be adjusted. Thanks for all ideas.</p>
  <pre><code>public boolean getAnalysisByUserId(final Integer userId) {
      Objects.requireNonNull(userId, &quot;Integer userId cannot be null.&quot;);
  
      final Query query = this.manager.createQuery(&quot;select count(a) from AnalysisRequest a where&quot; + &quot; a.userId = :userId&quot;,
          AnalysisRequest.class);
  
      query.setParameter(&quot;userId&quot;, userId);
  
      if (query.getSingleResult().equals(0)) {
        return false;
      }
      return true;
    }
  </code></pre>