-->
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.  [ 4 posts ] 
Author Message
 Post subject: Parameters in LIKE in HQL query
PostPosted: Thu Aug 11, 2005 3:05 pm 
Newbie

Joined: Sat Jul 23, 2005 7:19 pm
Posts: 11
I just want to know how I can pass parameters to a LIKE comparison:

sessionHb.createQuery(from Person as p where p.name like '%<parameter>%')

    Where <parameter> is I tried:

    ? and then writing .setString("a");


:param and then writing .setParameter("param", "a", Hibernate.STRING)

I know that I could pass as a normal concatenation:

String myString = "a";
sessionHb.createQuery(from Person as p where p.name like '%" + myString + "%')

I wanted to know if there is another way.


Top
 Profile  
 
 Post subject: How about this?
PostPosted: Thu Aug 11, 2005 3:11 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
sessionHb.createQuery(from Person as p where p.name like :param)

then .setParameter("param", "%a%", Hibernate.STRING)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 11, 2005 3:26 pm 
Expert
Expert

Joined: Thu Dec 04, 2003 12:36 pm
Posts: 275
Location: Bielefeld, Germany
Or even shorter. :)

Code:
query.setString("param", "%a%")


Best regards
Sven


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 11, 2005 4:56 pm 
Newbie

Joined: Sat Jul 23, 2005 7:19 pm
Posts: 11
Thank you very much! It was so easy, isn't it?


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