Home » Support » Forum » How to query for list of lists ?

How to query for list of lists ?

#1

Hi,

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(MSG.java:61)
at com.objectdb.o.QRC.G(QRC.java:609)
at com.objectdb.o.QRC.F(QRC.java:565)
at com.objectdb.o.QRC.E(QRC.java:514)
at com.objectdb.o.QRC.v(QRC.java:211)
at com.objectdb.o.QRC.u(QRC.java:166)
at com.objectdb.o.QRM.U4(QRM.java:245)
at com.objectdb.o.MST.U4(MST.java:947)
at com.objectdb.o.WRA.U4(WRA.java:290)
at com.objectdb.o.WSM.U4(WSM.java:113)
at com.objectdb.o.STC.r(STC.java:447)
at com.objectdb.o.SHN.aj(SHN.java:489)
at com.objectdb.o.SHN.K(SHN.java:156)
at com.objectdb.o.HND.run(HND.java:133)
at java.lang.Thread.run(Thread.java:662)

Is it a bug or am I doing something wrong?

#2

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)
#3

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.

 

#4

Adding more details:

 

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

Class:

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

    private static final long serialVersionUID = 1L;
    @Id
    @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.

#5
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