persistence@glassfish.java.net

Exception if Query.setParameter call is missing

From: Michael Bouschen <Michael.Bouschen_at_Sun.COM>
Date: Tue, 31 Jan 2006 16:47:55 +0100

Hi Linda, hi Mike,

Shelly and I were discussing exceptions with running EJBQL queries using
input parameters. The spec defines that an IllegalArgumentException is
thrown if a parameter is specified that does not correspond to a
parameter in the query string results in an IllegalArgumentException.
What is the expected exception if the EJBQL uses a parameter, but its
value is not defined on query execution, so the call Query.setParameter
is missing:
   Query query = em.createQuery(
     "SELECT c FROM Customer c WHERE c.name = :name");
   List result = query.getResultList();
I think method getResultList should indicate the error and throw an
exception.

Thanks!

Regards Michael