title: How to use ISNULL in jpa
body: <p>I have a table test1 having a column amount.I want to to retrieve the summation of all the columns.So I am using SUM function like this</p>
  
  <pre><code>SELECT SUM(cda.amount)FROM test cda
  </code></pre>
  
  <p>If the table is empty then it gives me null</p>
  
  <p>The equivalent JPA code is as follows</p>
  
  <p>If there is n</p>
  
  <pre><code>public Double sumAmount()
      {
          Query query=entityManagerUtil.getQuery("SELECT SUM(cda.amount)FROM test cda");
  
          Object result=query.getSingleResult();
          return (Double)result;
      }
  </code></pre>
  
  <p>Now In my controller I am adding this amount to principal;</p>
  
  <pre><code>Double total=prinicipal+daoImpl.sumAmount();
  </code></pre>
  
  <p>As <code>sumAmount()</code> returns <code>null</code> so I am getting NULLPOINTEREXCEPTION while adding here <code>prinicipal+daoImpl.sumAmount();</code></p>
  
  <p>So I am thinking to return 0 if the amount is null so tried ISNULL and IFNULL both like this</p>
  
  <pre><code>SELECT ISNULL(SUM(cda.amount),0) FROM test cda
  </code></pre>
  
  <p>but here it gives me the following error</p>
  
  <pre><code>No data type for node: org.hibernate.hql.ast.tree.MethodNode 
   \-[METHOD_CALL] MethodNode: '('
      +-[METHOD_NAME] IdentNode: 'ISNULL' {originalText=ISNULL}
  </code></pre>
  
  <p>So can anybody please tell me how to use properly ISNULL in JPA</p>