The fact that the parameter are indexed from zero can be effectively ignored by using named parameters, like so...
<query name="eg.DomesticCat.by.name.and.minimum.weight">< ![CDATA[
from eg.DomesticCat as cat
where cat.name = :name
and cat.weight > :weight
] ]></query>
Query q = sess.getNamedQuery("eg.DomesticCat.by.name.and.min imum.weight");
q.setString("name", name);
q.setInt("weight", minWeight);
List cats = q.list();
I'm sure that you'll agree - this is less error prone, more robust (when the query changes) and much more intuitive to read.
|