eclipse-ee4j / eclipse-ee4j/eclipselink

getResultList() not returning Tuple

Open
#778 5 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
246
Forks
202
Avg merge
1d 22h
Merged PRs (30d)
14

Description

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");

causes

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)

Tested with 2.7.4 and 2.7.6. I have seen a lot of examples showing this should return key/value pairs in Tuple class, for example here: https://stackoverflow.com/a/59840498/1827453

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the EntityManager.createQuery(..., Tuple.class) and getResultList() call shown in the reproducer, then verify the returned element type for the aliased Id and Project selections. Done means the query returns javax.persistence.Tuple instances so result.get(0).get("Project") works without a ClassCastException.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.