title: JPA/Hibernate returning BigDecimal not Long
body: <p>I'm computing a SUM grouped by months </p>
  
  <pre><code>Query q = entityManager.createNativeQuery(qlString);
  q.setParameter("program", program);
  @SuppressWarnings("unchecked")
  List&lt;Long&gt; resultList = (List&lt;Long&gt;) q.getResultList();
  long tend = System.currentTimeMillis();
  </code></pre>
  
  <p>When I pass in two resultsLists (closed:ResultsList of Closed items, closedLate: ResultsList of items Closed late) into a method that computes percentages, I get </p>
  
  <pre><code> javax.servlet.ServletException: java.lang.ClassCastException: java.math.BigDecimal cannot be cast to java.lang.Long
  </code></pre>
  
  <p>.</p>
  
  <pre><code>private List&lt;Long&gt; computeOTR(List&lt;Long&gt; closed, List&lt;Long&gt; closedLate) {
      List&lt;Long&gt; monthlyOTR = new ArrayList&lt;Long&gt;();
      long numerator;
      Long denominator;
      for (int i = 0; i &lt;11; i++) {
          numerator = closed.get(i) - closedLate.get(i); &lt;----java.lang.ClassCastException
          denominator = closed.get(i);
          long percentage = (int)(numerator * 100.0 / denominator + 0.5);
          monthlyOTR.add(i, percentage);
      }
      return monthlyOTR;
  </code></pre>
  
  <p>}</p>
  
  <p>In Eclipse debug mode closed is showing as BigDecimal. Why is this when I decalre</p>
  
  <p><code>List&lt;Long&gt; resultList = (List&lt;Long&gt;) q.getResultList();</code></p>
  
  <h1>EDIT-Hibernate Query:</h1>
  
  <pre><code>public List&lt;Long&gt; findClosedLateByProgram(String program) {
  
      long tstart = System.currentTimeMillis();
      //@formatter:off
      String qlString = "with PRJ as ( " +
              "select  trunc(END_DATE) as END_DATE,  " +
              "trunc(NEED_DATE) as NEED_DATE   " +
              "from (SELECT UNIQUE * FROM TEST where PROGRAM_NAME = :program " +
              "AND ACTION_BY_ORG = 'AAA') " +
              "),  " +
              "DATES as ( select add_months(trunc(last_day(SYSDATE)), level-7) as thedate  " +
              "from dual connect by level &lt;= 12  )   " +
              "SELECT nvl(sum(case when NEED_DATE &lt;  trunc(thedate,'mm') AND END_DATE between trunc(thedate,'mm') and thedate then 1 end), 0 ) as CLOSED_LATE  " +
              "FROM  DATES, PRJ  " +
              "GROUP BY thedate ORDER BY thedate";
      //@formatter:on
  
      Query q = entityManager.createNativeQuery(qlString);
      q.setParameter("program", program);
      // q.setParameter("today",date, TemporalType.DATE);
  
      @SuppressWarnings("unchecked")
      List&lt;Long&gt; resultList =  q.getResultList();
      long tend = System.currentTimeMillis();
      long elapsed = tend-tstart;
      System.out.println("Elapsed Time For Closed But Late: " + elapsed);
      return resultList;
  }
  </code></pre>
  
  <h1>EDIT 2</h1>
  
  <p>I think I am stuck with a BigDecimal?
  <a href="http://weblogs.java.net/blog/mb124283/archive/2007/04/java_persistenc.html" rel="noreferrer">http://weblogs.java.net/blog/mb124283/archive/2007/04/java_persistenc.html</a></p>