persistence@glassfish.java.net

EJBQL: fix problem with order of Query.setParameter call for named parameters

From: Michael Bouschen <Michael.Bouschen_at_Sun.COM>
Date: Mon, 23 Jan 2006 13:20:55 +0100

Hi Tom,

attached you find a fix for glassfish issue 183:
   https://glassfish.dev.java.net/issues/show_bug.cgi?id=183

With the current code you need to call Query.setParameter in the same
order as the named input parameters appear in the EJBQL text. Otherwise,
the generated SQL uses the parameter values in the wrong order:
   Query query = em.createQuery(
     "SELECT o FROM Order o WHERE o.orderId BETWEEN :lower AND :upper");
   query.setParameter("upper", new Integer(2));
   query.setParameter("lower", new Integer(1));
results in the following generated SQL:
   SELECT ID, ... FROM ORDER_TABLE WHERE (ID BETWEEN 2 AND 1)
Please note, the correct BETWEEN clause would have the values swapped.

I changed the parameter handling in class EJBQueryImpl and replaced the
lists of parameter names and values by a map. The internal method
processParameters now returns a list of parameter values that are in the
expected order. Please have a look.

Thanks!

Regards Michael