-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Problem using Query.setParameter
PostPosted: Wed Aug 05, 2009 10:37 am 
Newbie

Joined: Wed Aug 05, 2009 10:22 am
Posts: 1
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.