此查询SELECT i FROM Item i WHERE 1 = 1 AND UPPER(i.nome) LIKE %:nome% ORDER BY UPPER(i.nome)
有什么问题?我试过在LIKE'%:nome%'中使用单引号和不使用单引号,但是它不起作用。
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)
最佳答案
如here所述,您需要在设置参数时用%
包裹值,例如:
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()+"%");