The Java EE 6 Tutorial

Positional Parameters in Queries

You may use positional parameters instead of named parameters in queries. Positional parameters are prefixed with a question mark (?) followed the numeric position of the parameter in the query. The Query.setParameter(integer position, Object value) method is used to set the parameter values.

In the following example, the findWithName business method is rewritten to use input parameters:

public List findWithName(String name) {
    return em.createQuery(
        “SELECT c FROM Customer c WHERE LIKE ?1”)
        .setParameter(1, name)

Input parameters are numbered starting from 1. Input parameters are case-sensitive, and may be used by both dynamic and static queries.