Uploaded image for project: 'OpenJPA'
  1. OpenJPA
  2. OPENJPA-2553

JPQL AVG returns Int instead of Double wrt. @ElementCollection

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 2.4.0
    • Fix Version/s: None
    • Component/s: query
    • Labels:
      None
    • Environment:
      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>();
      ...
      }
      

      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.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              apache_fan Apache Fan
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: