-->
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.  [ 3 posts ] 
Author Message
 Post subject: HQL - another ilike/lower problem
PostPosted: Thu Sep 03, 2009 12:21 pm 
Newbie

Joined: Thu Sep 03, 2009 12:10 pm
Posts: 2
Hi,

As mentioned in the subject I have HQL-ilike problem.
I do not use Criteria but Query :

Code:
StringBuffer req = new StringBuffer();
req.append("SELECT count(misc)");
req.append(" FROM MiscValueObject AS misc");
req.append(" WHERE lower(misc.name) like lower('%?%')");
Query q = session.createQuery(req.toString());
q.setString(0, name);
//->Ordinal parameter not found


I have tried too :
Code:
req.append(" WHERE lower(misc.name) like lower('%:param%')");
Query q = session.createQuery(req.toString());
q.setString("param", name)
//->"param" not found


Each time, or ? is not found as an ordinal parameter, or "param" is not found too. I have tried many other possibilities but I could not find any way to make it work. Except the very ugly (due to SQL injection):

Code:
req.append(" WHERE lower(misc.name) like lower('%" + param + "%')");
Query q = session.createQuery(req.toString());
q.setString("param", name)
//->prone to SQL Injection


Any Idea to make it work ?

Thanks

Guillaume


Top
 Profile  
 
 Post subject: Re: HQL - another ilike/lower problem
PostPosted: Fri Sep 04, 2009 2:23 am 
Newbie

Joined: Wed Oct 01, 2008 2:27 pm
Posts: 18
How about:

Code:
...
req.append(" WHERE lower(misc.name) like ?");
Query q = session.createQuery(req.toString());
q.setString(0, '%' + name.toLowerCase() + '%');


Top
 Profile  
 
 Post subject: Re: HQL - another ilike/lower problem
PostPosted: Fri Sep 04, 2009 4:06 am 
Newbie

Joined: Thu Sep 03, 2009 12:10 pm
Posts: 2
Thanks that is the solution ;)


Guillaume


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