Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » InvalidQuery key [...] exception with CriteriaQuery(Criteria queries don't work out of the box)
InvalidQuery key [...] exception with CriteriaQuery [message #1219065] Sat, 30 November 2013 12:44 Go to next message
Okihara Herbst is currently offline Okihara Herbst
Messages: 2
Registered: November 2013
Junior Member
Disclaimer: I'm no EclipseLink specialist. My JPA experience to date has been with Hibernate only and the snippet below or the rest of the code is not using any vendor specific annotations. It is from a JPA 2.0 project.

Migrating from Hibernate 4.2.6 to EclipseLink 2.4.2 (or 2.5.1) for a project, many criteria queries that used to run correctly now abruptly break up with EclipseLink saying, for instance:

Exception Description: Invalid query key [
Query Key posts Base com.comax.model.mailing.Post] 
in expression.Query: ReportQuery(referenceClass=Post )

where Point entity has a unidirectional 1-N relationship to Post.

The query is
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Post> q = cb.createQuery(Post.class);
Root<Point> root = q.from(Point.class);
Join<Point, Post> p1 = root.join("posts", JoinType.INNER);
Path<String> city = p1.get("city"); 

q.select(p1).distinct(true).where(cb.like(city, "L%"));

TypedQuery<Post> tq = em.createQuery(q);
List<Post> results = tq.getResultList();

i.e., selecting distinct `Post` entities whose `city` (String) attribute begins with `L` and navigating from the `Point` root.

The error message leaves me perplex. These Post and Point entities both inherit (JOINED strategy) from a common Base entity that is mentioned in Query Key posts Base. But I don't think that this is the issue. I tried querying an attribute that doesn't exist, like
root.get("xyz")
and EclipseLink gives a totally different error.

Moreover, the JPQL equivalent
List<Post> results = em.createQuery(
    "SELECT DISTINCT post FROM Point p JOIN p.posts post WHERE post.city LIKE 'L%' ORDER BY post.city", 
    Post.class).getResultList();

runs as expected.

How do I achieve this? Or am I missing something? Is there something specific to EclipseLink when it comes to criteria queries like setting a property in persistence.xml?

I read the exception description about query keys but I don't see why (or where) I'm supposed to create one.

Any help here would be most appreciated. Thank you folks.
Re: InvalidQuery key [...] exception with CriteriaQuery [message #1219192 is a reply to message #1219065] Mon, 02 December 2013 10:09 Go to previous message
Okihara Herbst is currently offline Okihara Herbst
Messages: 2
Registered: November 2013
Junior Member
is this case so isolated? i thought this was a common pitfall.
Previous Topic:JPA and treat keyword
Next Topic:ExpressionBuilder is null when there are concurrent request
Goto Forum:
  


Current Time: Sat Jul 26 07:29:37 EDT 2014

Powered by FUDForum. Page generated in 0.02867 seconds