-->
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: Using like '%xxx%' with parameter
PostPosted: Fri Mar 09, 2007 4:42 am 
Beginner
Beginner

Joined: Sun Jul 31, 2005 6:15 pm
Posts: 28
Hi,

I like to be able to use parameter with expression

like '%mysearchtext%'

For instance:

session.createQuery("From cat where name like '%:search%')
.setParameter("search", search);

How this is possible ?

Thank You


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 10, 2007 7:50 am 
Expert
Expert

Joined: Thu May 26, 2005 9:19 am
Posts: 262
Location: Oak Creek, WI
Hi,

Use criteria API

Criteria criteria = session.createCriteria(Cat.class);
criteria.add(Expression.like("search", cat.getSearch()+"%"));
List list = criteria.list();


Use you own combinations of search exploring criteria API.

Have fun:-)

_________________
RamnathN
Senior Software Engineer
http://www.linkedin.com/in/ramnathn
Don't forget to rate.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 11, 2007 3:03 am 
Newbie

Joined: Thu Mar 08, 2007 8:49 am
Posts: 11
Location: Hyd
hi,

try like this

session.createQuery("From cat where name like :search)
.setParameter("search", "%"+search+"%");

_________________
Thanks&Regards
Sunil k


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.