3

When I execute the following code

return entityManager
            .createQuery("select a from Article where a.slug = ?1", Article.class)
            .setParameter(1, slug)
            .getSingleResult();

I get the following exception

java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager: 
Exception Description: Syntax error parsing the query [select a from Article where a.slug = '?1'], line 1, column 22: syntax error at [where].
Internal Exception: MismatchedTokenException(77!=78)
    at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1328)

I'm using JPA 2 with EclipseLink 2.0.2.

What is wrong with my query?

2 Answers 2

8

... From Article a ... (missing alias)

Sign up to request clarification or add additional context in comments.

Comments

1

Well, the answer has alredy given.. But what I dont like about JPQL, you have to put an identifier after Entity name, but it is uncessary if your from clause does have only one Entity. Most of time, I also forget to put that unnecessarily required identifier. I wish I would write the above query as below;

select * from Article where slug = ?1

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.