0

I have tried this solution:

List<javax.persistence.Tuple> result = entityManager.createQuery("select f.Id as Id, f.Project as Project from FirewallRequest f", javax.persistence.Tuple.class)
                                                    .getResultList();
result.get(0).get("Project");

I'm getting this:

java.lang.ClassCastException: class [Ljava.lang.Object; cannot be cast to class javax.persistence.Tuple ([Ljava.lang.Object; is in module java.base of loader 'bootstrap'; javax.persistence.Tuple is in unnamed module of loader java.net.URLClassLoader @7a9273a8)

So it seems to be returning List of Objects instead of Tuples. Is Tuple not supported by EclipseLink or what is the problem?

Debugger shows it's actually a Vector of Objects:

enter image description here

I'm using TomEE 8 which uses EclipseLink 2.7.4.v20190115 for JPA. I could try with JPA Criteria Query but I'm converting from SQL and it would be easier to convert it to JPQL.

Edit 1

Here is an answer from writer of the linked article which also suggests this should work.

Edit 2

EclipseLink issue created.

Edit 3

Luckily it works with JPA Criteria Query (CriteriaBuilder#createTupleQuery()). It's more work to convert SQL to that but at least it works.

Panu Haaramo
  • 2,932
  • 19
  • 41

1 Answers1

0

A query with projection returns always List<Object[]>

As long as you don't use constructor expression with

select new x.y.Tuple(f.Id, f.Project) from FirewallRequest f

But then you need a Tuple with a constructor that matches the projection.

Simon Martinelli
  • 34,053
  • 5
  • 48
  • 82