-->
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: named parameter in like clause
PostPosted: Tue May 29, 2007 10:52 am 
Regular
Regular

Joined: Sat May 20, 2006 3:49 am
Posts: 78
hello,

I have a problem with the following query:

Query query = em.createQuery(" SELECT g.id, g.codeId, g.txtName from PatientGroup as g WHERE lower(g.codeId) like '?1%'");
query.setParameter(1, codeId.toLowerCase());

the parameter ?1 is not found within the like-clause. I get the error "org.hibernate.QueryParameterException: could not locate named parameter [1]"

I can only find examples of ejb-ql without parameters in like-queries...
any ideas?


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 29, 2007 3:19 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
try without the quotes

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 30, 2007 4:18 am 
Regular
Regular

Joined: Sat May 20, 2006 3:49 am
Posts: 78
without the quotes I get the following error:

"java.lang.IllegalArgumentException: org.hibernate.QueryException: unexpected char: '%' [ SELECT g.id, g.codeId, g.txtName from org.dseas.base.model.PatientGroup as g WHERE lower(g.codeId) like ?1%]"


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 30, 2007 12:38 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
oh % should be included in your parameter value
like ?1

setParameter(1, "foo%")

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 30, 2007 1:25 pm 
Regular
Regular

Joined: Sat May 20, 2006 3:49 am
Posts: 78
emmanuel wrote:
oh % should be included in your parameter value
like ?1

setParameter(1, "foo%")


thx, that 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.