Reputation: 6372
What is wrong with this query: SELECT i FROM Item i WHERE 1 = 1 AND UPPER(i.nome) LIKE %:nome% ORDER BY UPPER(i.nome)
? I tried with and without single quotes in LIKE '%:nome%' but it doesn't work.
Exception in thread "JavaFX Application Thread" java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager:
Exception Description: Syntax error parsing [SELECT i FROM Item i WHERE 1 = 1 AND UPPER(i.nome) LIKE %:nome% ORDER BY UPPER(i.nome)].
[56, 63] The identification variable '%:nome%' is not following the rules for a Java identifier.
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1605)
Upvotes: 0
Views: 1464
Reputation: 30849
As explained here, you need to wrap the value with %
while setting the parameters, e.g.:
query = em.createQuery("SELECT i FROM Item i WHERE 1 = 1 AND UPPER(i.nome) LIKE :nome ORDER BY UPPER(i.nome)");
query.setParameter("nome","%"+nome.toUpperCase()+"%");
Upvotes: 1