Syntax error in JPA request

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 am using JPA 2 with EclipseLink 2.0.2.

What is wrong with my request?

+3
source share
2 answers

... From article a ... (nickname missing)

+8
source

Well, the answer was alredy. But what I don't like about JPQL is that you need to put the identifier after the Entity name, but it is not needed if your proposal has only one Entity. Most of the time I also forget to put an unnecessary identifier. I am sorry that I will not write the above request as shown below;

select * from Article where slug = ?1
+1
source

Source: https://habr.com/ru/post/1789212/


All Articles