Apache Fan created OPENJPA-2553: ----------------------------------- Summary: JPQL AVG returns Int instead of Double wrt. @ElementCollection Key: OPENJPA-2553 URL: https://issues.apache.org/jira/browse/OPENJPA-2553 Project: OpenJPA Issue Type: Bug Components: query Affects Versions: 2.4.0 Environment: Apache Tomee plus 1.7.1, openjpa-2.4.0-nonfinal-1598334.jar, hsqldb-2.3.2, H2DB-2014-12-19 Reporter: Apache Fan
The following JPQL query is executed to get the average of values stored in a Map. {noformat} @NamedQueries({ @NamedQuery(name = "selectFromMap", query = "SELECT new dao.entity.AggregationResultHolder(AVG(p), KEY(p)) FROM Evaluation e, IN (e.scores) p " + "WHERE e.subject.id=:subjectId GROUP BY KEY(p)") }) {noformat} Entity: {noformat} public class Evaluation { ... @ElementCollection @MapKeyColumn(name = "criteria_id") @Column(name = "criteria_score") private Map<Criteria, Integer> scores = new HashMap<Criteria, Integer>(); ... } {noformat} - *Expected behaviour:* the AVG value is returned as Double (according to http://openjpa.apache.org/builds/2.3.0/apache-openjpa/docs/jpa_langref.html#jpa_langref_aggregates ) - *Experienced behaviour:* the average is returned as Integer (and exception is thrown if the AggregationResultHolder class' constructor is not Integer-based). Unfortunately this way the fraction digits are lost. *Workaround:* after modifying the Map to <Criteria, Double> in the entity, the query returns Doubles for the average (however the fraction digits are still lost in case of HSQLDB). Obviously it is a sub-optimal solution, as the schema has to be changed. -- This message was sent by Atlassian JIRA (v6.3.4#6332)