The Java EE 5 Tutorial

Positional Parameters in Queries

You may alternately use positional parameters in queries, instead of named parameters. 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.