Details
-
Bug
-
Status: Open
-
Major
-
Resolution: Unresolved
-
2.4.0
-
None
-
None
-
Apache Tomee plus 1.7.1, openjpa-2.4.0-nonfinal-1598334.jar, hsqldb-2.3.2, H2DB-2014-12-19
Description
The following JPQL query is executed to get the average of values stored in a Map.
@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)") })
Entity:
public class Evaluation { ... @ElementCollection @MapKeyColumn(name = "criteria_id") @Column(name = "criteria_score") private Map<Criteria, Integer> scores = new HashMap<Criteria, Integer>(); ... }
- 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.