How to query for list of lists ?



I have a problem with constructing query, that gets only embedded list of integers from Entity. Here's the example :

Query query = em.createQuery("SELECT i.filterDescription FROM Inspiration i");
List<List<Integer>> result = query.getResultList();

where Inspiration is like this :

@Entity(name = "Inspiration")
public class Inspiration implements Serializable {
@ElementCollection(fetch = FetchType.EAGER)
protected List<Integer> filterDescription;

Whene i try to run this code I get error :

Caused by: com.objectdb.o.UserException: Invalid result expression 'java.util.List' for an aggregate query
at com.objectdb.o.MSG.d(
at com.objectdb.o.QRC.G(
at com.objectdb.o.QRC.F(
at com.objectdb.o.QRC.E(
at com.objectdb.o.QRC.v(
at com.objectdb.o.QRC.u(
at com.objectdb.o.QRM.U4(
at com.objectdb.o.MST.U4(
at com.objectdb.o.WRA.U4(
at com.objectdb.o.WSM.U4(
at com.objectdb.o.STC.r(
at com.objectdb.o.SHN.aj(
at com.objectdb.o.SHN.K(

Is it a bug or am I doing something wrong?


Collections cannot be specified directly in the SELECT clause.

But this should work:

SELECT f FROM Inspiration i JOIN i.filterDescription f
ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)

When I tried using the as described by support it only returns the first one as an Integer and not a list of all of them.



Adding more details:


I get the same error: "Invalid result expression 'java.util.List' for an aggregate query"


@Table(name = "pulseDataWareHouse")
public class PulseDataWareHouse implements Serializable {

    private static final long serialVersionUID = 1L;
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Integer id;
    @Column(name= "reviewSnippets")
    @ElementCollection(fetch = FetchType.EAGER)
    private List<String> reviewSnippets;



Finally the query is: 

SELECT  w.reviewSnippets FROM PulseDataWareHouse w

That throws the error.


When following the example posted by support,

SELECT s FROM PulseDataWareHouse w JOIN w.reviewSnippets s

I don't get an error but instead only the get the first entry String from reviewSnippets.


Thanks for any help.

SELECT  w.reviewSnippets FROM PulseDataWareHouse w

You cannot select a list, so this is an invalid JPQL query.

SELECT s FROM PulseDataWareHouse w JOIN w.reviewSnippets s

This should work, and the results should include all the strings. Please provide a full test case that demonstrates this issue.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)

Post Reply

To post a reply and/or subscribe to update notifications - please login