-->
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: Underscore character is ignored in query using criteria
PostPosted: Wed Sep 28, 2005 6:24 pm 
Newbie

Joined: Mon May 03, 2004 11:53 pm
Posts: 7
The underscore character "_" is ignored in our search criteria. For example a search for "BANK_1" returns "BANK 1" ignoring the underscore.

Search criteria: criteria.add(Restrictions.ilike("nameTx", searchName, MatchMode.ANYWHERE));

searchName = "BANK_1"

We are using hibernate 3. Can anyone provide any insight as to why the underscore is ignored ? Any suggestions will be appreciated.

Thank you.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 28, 2005 8:31 pm 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
underscores are often wildcards for a single character in SQL


Top
 Profile  
 
 Post subject: Underscore character is ignored in query using criteria
PostPosted: Thu Sep 29, 2005 3:28 pm 
Newbie

Joined: Mon May 03, 2004 11:53 pm
Posts: 7
Thanks for your reply. I just needed to treat the underscore as an escape character.

The following worked in Hibernate 3:
criteria.add(Restrictions.ilike("nameTx", "B\\_1", MatchMode.ANYWHERE));

The following did not appear to work:
criteria.add(Restrictions.ilike("nameTx", "B_1 escape _", MatchMode.ANYWHERE));

srceString.replaceAll("_", "\\_")


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 29, 2005 3:32 pm 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
don't forget to rate ;)


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.