Search code examples
javajpql

jpql SUM one column


I am trying to add up all the prices in one column, but it outputs a ridiculous total. Please help, not sure if my query is incorrect. Thanks.

@NamedQuery(name = "Tyrerange.totalCost", query = "SELECT SUM(t.dblTyreCost) FROM Tyrerange t"),    

double totalCost = (double) em.createNamedQuery("Tyrerange.totalCost").getSingleResult();

document.add(new Paragraph(String.valueOf((df.format(totalCost)))));

Solution

  • The query looks ok. Maybe the cached values are being read. Create a new query and sum some other column to check this.