-->
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.  [ 6 posts ] 
Author Message
 Post subject: A simple query.Parameter does not exist as a named parameter
PostPosted: Thu Oct 23, 2008 12:04 am 
Newbie

Joined: Wed Oct 22, 2008 10:20 pm
Posts: 11
Hi,

I am using Hibernate 3.0 and oracle 9i DB.
I am trying to run this query below:

Query q = session.createQuery("from Users u where u.name = :i_name");
q.setString("name", i_name);

I keep getting this error:
Parameter name does not exist as a named parameter in [from Users u where u.name = :i_name].

My Users.hbm.xml has this 'name' parameter.
Is there anything wrong with my query or any setting I need to configure?

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 23, 2008 12:26 am 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
the name of the parameter is "i_name", not "name".

The name of the variable holding the parameter value is coincidentally i_name, but that is irrelevant.

_________________
Gonzalo Díaz


Top
 Profile  
 
 Post subject: Another problem
PostPosted: Thu Oct 23, 2008 2:55 am 
Newbie

Joined: Wed Oct 22, 2008 10:20 pm
Posts: 11
Yes, I have change it, now I have encountered another problem.
If my input value is a string, no result is return. However, if I used another field is that integer, it can works. Is there different setting between 'setInteger' & 'setString' ? Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 23, 2008 7:39 am 
Regular
Regular

Joined: Mon Jan 22, 2007 10:32 am
Posts: 101
Not sure what is the problem that you are facing now but setString expects second parameter to be a string and setInteger expects that to be integer.

_________________
Please rate this post if you find it helpful


Top
 Profile  
 
 Post subject: setString can't works
PostPosted: Thu Oct 23, 2008 7:40 pm 
Newbie

Joined: Wed Oct 22, 2008 10:20 pm
Posts: 11
I tried 'setInteger' for integer field, it can works but
when I tried 'setString' for varchar field, it can't works...very weird?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 24, 2008 6:30 pm 
Newbie

Joined: Fri Oct 24, 2008 6:24 pm
Posts: 1
I had exactly the same problem as you. It sounds very obvious - check that the value you are matching against is the same as the value you're passing as the parameter value, for example:

cn=someuser, ou=businessunit, dc=example, dc=com

is not the same as:

cn=someuser,ou=businessunit,dc=example,dc=com

In this case (which is based on the problem I experienced) it wasn't obvious to me that the first string had spaces where as the second one didn't.

I found that when the two values were exactly the same (as you would expect for an =) setString worked fine.


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

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.