Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Syntax error in JPA query

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?

like image 862
deamon Avatar asked Jun 04 '26 22:06

deamon


1 Answers

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

like image 199
Clement P Avatar answered Jun 07 '26 11:06

Clement P



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!