ObjectDB ObjectDB

Problem of query With an aggregate function



I would know if this type of query is supported By JPA:

select sum(nb1), sum(nb2), sum(nb3) from table

If yes I have this methode that return a list of Long:

  public List<Long> sommeClassesRep(Choix choix) {
      Query listClassRepHost = em.createQuery("SELECT SUM(h.nb1xx), SUM(h.nb2xx),SUM(h.nb3xx),SUM(h.nb4xx),SUM(h.nb5xx) FROM HttpEntity h WHERE h.host = :host and h.date_http BETWEEN to_date(:startDate,'dd/mm/yyyy HH24:mi:ss') AND to_date(:endDate,'dd/mm/yyyy HH24:mi:ss')");
    listClassRepHost.setParameter("host",choix.getHost() );
    listClassRepHost.setParameter("startDate", convert.convertDateTime(choix.getStartdate()) );
    listClassRepHost.setParameter("endDate", convert.convertDateTime(choix.getEndDate()));
    List<BigDecimal[]> listRes = new ArrayList<BigDecimal[]>();
    listRes  =  (List<BigDecimal[]>) listClassRepHost.getResultList();
    List<Long> listSommeLong = new ArrayList<Long>();
    for (BigDecimal[] bigDecimals : listRes) {
      for (int i = 0; i < bigDecimals.length; i++) {
    return listSommeLong;    


When i debug i have a sever error that Object can't cast to Big decimal 

and my query always retuen a list of Long like this : [120,0,314,464646,0]


can you help me please



The query is valid. The return type depends on the type of the fields (nb1, nb2, ...).

If the type of your fields is long (or Long) the result should be Long instances as reported.

ObjectDB Support


To post on this website please sign in.