-->
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.  [ 5 posts ] 
Author Message
 Post subject: Using 'like' and setting parameters
PostPosted: Tue Sep 22, 2009 11:24 pm 
Newbie

Joined: Thu Sep 11, 2008 6:50 pm
Posts: 5
Hey guys, so I have a query like this:

Code:
select u from UserEntity u  where u.firstName like '%?1%'


but I get

Code:
org.hibernate.QueryParameterException: could not locate named parameter [1]; nested exception is java.lang.IllegalArgumentException: org.hibernate.QueryParameterException: could not locate named parameter [1]


when I try to execute
Code:
query.setParameter(1, firstName)


Any ideas?


Top
 Profile  
 
 Post subject: Re: Using 'like' and setting parameters
PostPosted: Wed Sep 23, 2009 12:50 am 
Beginner
Beginner

Joined: Wed Jun 17, 2009 9:03 pm
Posts: 31
Location: mumbai
Hi

Check if this works.

Code:
select u from UserEntity u  where u.firstName like '%' ||?1 || '%'


Top
 Profile  
 
 Post subject: Re: Using 'like' and setting parameters
PostPosted: Wed Sep 23, 2009 2:20 am 
Newbie

Joined: Thu Sep 11, 2008 6:50 pm
Posts: 5
Nope. I got exactly the same error.


Top
 Profile  
 
 Post subject: Re: Using 'like' and setting parameters
PostPosted: Wed Sep 23, 2009 4:38 am 
Beginner
Beginner

Joined: Wed Jun 17, 2009 9:03 pm
Posts: 31
Location: mumbai
Hi

Check this link

[url]
viewtopic.php?t=943637&highlight=
[/url]


Top
 Profile  
 
 Post subject: Re: Using 'like' and setting parameters
PostPosted: Wed Sep 23, 2009 11:56 pm 
Newbie

Joined: Thu Sep 11, 2008 6:50 pm
Posts: 5
Thanks. Putting the % in the parameter argument to set parameter worked.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.