-->
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: how to use wild cards with substituted values in HQL
PostPosted: Tue Jun 26, 2007 3:29 pm 
Newbie

Joined: Tue Jun 26, 2007 3:24 pm
Posts: 11
I am trying to do a query along the lines of
Code:
getHibernateTemplate().find("FROM User AS u WHERE u.name LIKE ?", username);

except I want wildcard characters (% signs) to be appended to the username on both sides without being escaped. How would I do this, while still insuring that the username is escaped?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 26, 2007 3:39 pm 
Senior
Senior

Joined: Tue Jun 12, 2007 4:49 pm
Posts: 127
Location: India
Try putting the search string in single quote.

Hibernate will not do it automatically, if thats what you are looking for.

*Please do rate if it helps*

Regards,
Jitendra


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 26, 2007 3:59 pm 
Newbie

Joined: Tue Jun 26, 2007 3:24 pm
Posts: 11
^-I'm sorry, I'm not exactly sure what you meant. Did you mean something like this:
Code:
getHibernateTemplate().find("FROM User AS u WHERE u.name LIKE '%?%'", username);


?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 26, 2007 4:24 pm 
Senior
Senior

Joined: Tue Jun 12, 2007 4:49 pm
Posts: 127
Location: India
Instead you can try:

Code:
getHibernateTemplate().find("FROM User AS u WHERE u.name LIKE ?", "%"+username+"%");



*Please do rate if it helps*

Regards,
Jitendra


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 26, 2007 4:56 pm 
Newbie

Joined: Tue Jun 26, 2007 3:24 pm
Posts: 11
edit: Thanks, it 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.