Monthly Archives: October 2016

Named parameter not found in JPA/Hibernate native SQL queries

When using named parameters in native SQL queries with Hibernate implementation of the Java Persistence API (JPA), you may run into the following error

org.springframework.dao.InvalidDataAccessApiUsageException: Parameter with that name [orderId] did not exist; 
nested exception is java.lang.IllegalArgumentException: Parameter with that name [orderId] did not exist

This happens even if the named parameter was properly set, as in the following example :

For example :

void update(EntityManager em) {
    Query q = em.createNativeQuery("SELECT * FROM orders where id = :orderId;");
    q.setParameter("orderId", "1234");
    q.executeUpdate();
}

The issue comes from Continue reading