Selecting sets of JPA values

0

I have the following problem:

I have a table with a list of values for a composite key. Here's an example:

ID | ItemCode | Localidade | Preco
---+----------+------------+-------
01 |      001 |        001 |   3.5
02 |      002 |        001 |   4.5
03 |      001 |        002 |   5.5
04 |      001 |        003 |   5.0
05 |      003 |        002 |  15.3
06 |      002 |        001 |   4.2
07 |      001 |        001 |   5.3

What I need is to "group" based on the combination of the ItemCode and Location columns. But I need to use the Price column to do a series of calculations. The issue is that GROUP BY does not allow this listing, the Price column should be included in an aggregate function such as SUM () or AVG (). How to list all prices for a particular item and location. Since I do not know the values in any of the columns and I need to use all the records, always selecting all records for each ItemCode and Location.

The return I wish would be like this:

ItemCode | Localidade | Preco
---------+------------+-------
     001 |        001 |   [3.5, 5.3]
     001 |        002 |   [5.5]
     001 |        003 |   [5.0]
     002 |        001 |   [4.5, 4.2]
     003 |        002 |   [15.3]

I do not know if this is possible for JPA. I think I'll have to sort through the two columns and go through the ResultSet to mount the array.

    
asked by anonymous 26.10.2015 / 19:09

0 answers