Given some Java code like:
Criteria criteria = Criteria.forClass(Projet.class);
criteria.add(Restrictions.eq("campagne.id", idCampagne));
DAO.findByCriteria(criteria);
Using EclipseLink JPA provider (I updated the pom.xml), I get this error:
java.lang.IllegalArgumentException: An exception occurred while creating a
query in EntityManager:
Exception Description: Syntax error parsing the query [select this from Projet
as this where this.campagne.id=?], line 0, column -1: unexpected end of query.
Internal Exception: NoViableAltException(-1!=[792:1:
comparisonExpressionRightOperand returns [Object node] : (n=
arithmeticExpression | n= nonArithmeticScalarExpression | n= anyOrAllExpression
);])
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1373)
at com.szczytowski.genericdao.criteria.Criteria.prepareQuery(Criteria.java:333)
at com.szczytowski.genericdao.criteria.Criteria.list(Criteria.java:236)
at com.szczytowski.genericdao.impl.GenericDao.findByCriteria(GenericDao.java:319)
[...]
It looks like "select this from Projet as this where this.campagne.id=?" is not
a valid JPQL query.
AFAIK numbered parameters must be specified with an index, e.g.:
"select this from Projet as this where this.campagne.id=?1"
Whereas Hibernate HQL doesn't need this index, that's why included tests for
criteria succeed.
Original issue reported on code.google.com by damiano....@gmail.com on 27 Jan 2011 at 11:24
Original issue reported on code.google.com by
damiano....@gmail.com
on 27 Jan 2011 at 11:24