I'm using Java Persistence and Hibernate 3.2.4.
I want to submit a query using named parameters and Query.setParameter(). When I do this I do not get any exceptions but I also do not get any data. I've turned on debug and I see the parameters being set.
If I do the query without the named parameters (just concatenate the values in the select), it works.
This is the code that doesn't return the data:
final String LEAFS_BY_CENTER_CLASS_SELECT = "select model from Leaf model " + "join model.leafAttrRels as centerRel " + "join model.leafAttrRels as classRel " + "join centerRel.attribute as centerAttr " + "join classRel.attribute as classAttr " + "where classAttr.name = 'CLASS' " + "and centerAttr.name = 'CENTER'" + "and centerAttr.stringValue = :centerName " + "and classAttr.stringValue = :className"; Query query = getEntityManager().createQuery(LEAFS_BY_CENTER_CLASS_SELECT);
query.setParameter("centerName", centerName); query.setParameter("className", className); List<Leaf> results = query.getResultList();
This is the code that returns the data:
final String LEAFS_BY_CENTER_CLASS_SELECT = "select model from Leaf model " + "join model.leafAttrRels as centerRel " + "join model.leafAttrRels as classRel " + "join centerRel.attribute as centerAttr " + "join classRel.attribute as classAttr " + "where classAttr.name = 'CLASS' " + "and centerAttr.name = 'CENTER'" + "and classAttr.stringValue = '" + className + "'" + "and centerAttr.stringValue = '" + centerName + "'"; Query query = getEntityManager().createQuery(LEAFS_BY_CENTER_CLASS_SELECT);
List<Leaf> results = query.getResultList();
Thanks for any help! Johnny
|