Returning result of count native query using EntityManager in Java?
<p>I have the following <code>SQL Query :</code></p>
<pre><code>SELECT COUNT(*) FROM DOG where ID = 'SampleId';
</code></pre>
<p>I am trying to write this in <code>java</code> :</p>
<pre><code>public int returnCountOfDogTable(String id){

        String sql= &quot;SELECT COUNT(*) FROM DOG WHERE ID =:id&quot;;
        Query query = persistence.entityManager().createNativeQuery(sql);
        query.setParameter(&quot;id&quot;, id);
        List&lt;Integer&gt; resultList = query.getResultList();
        int result = resultList.get(0);
        return result;
    }
</code></pre>
<p>However I get this exception:</p>
<pre><code>java.lang.ClassCastException: java.math.BigDecimal cannot be cast to java.lang.Integer
</code></pre>
<p>How can I solve this?</p>