Positional parameters in JPQL queries are not supported. E.g.
public List findWithName(String name) {
return em.createQuery(
“SELECT c FROM Customer c WHERE c.name LIKE ?1”)
.setParameter(1, name)
.getResultList();
}
will return an empty list, but
public List findWithName(String name) {
return em.createQuery(
“SELECT c FROM Customer c WHERE c.name LIKE :name”)
.setParameter("name", name)
.getResultList();
}
will return the desired result (given some Customer objects in the DB). A fully working example to reproduce the issue can be found in https://github.com/dadrus/jpa-unit/blob/master/integration-test/base/src/main/java/eu/drus/jpa/unit/test/AbstractInitialDataSetsTest.java (test4() method line 80). Just replace the query in line 82 one time by
final TypedQuery<Depositor> query = manager.createQuery("SELECT d FROM Depositor d WHERE d.surname=?1", Depositor.class);
query.setParameter(1, "Doe");
and one time by
final TypedQuery<Depositor> query = manager.createQuery("SELECT d FROM Depositor d WHERE d.surname=:surname", Depositor.class);
query.setParameter("surname", "Doe");
and run the tests to see the effects. With Hibernate OGM and MongoDB it can be run using https://github.com/dadrus/jpa-unit/blob/master/integration-test/jpa-mongodb-hibernate-ogm-test/src/test/java/eu/drus/jpa/unit/test/InitialDataSetsTest.java. If you run the same tests but for a RDBMS (e.g. from https://github.com/dadrus/jpa-unit/blob/master/integration-test/jpa2.1-hibernate-test/src/test/java/eu/drus/jpa/unit/test/InitialDataSetsTest.java) everything is fine, both cases work as expected. This limitation makes a usage of libraries like Deltaspike Data, which e.g. generate JPQL queries based on method signatures of a DAO/Repository definitions impossible without workarounds. |