-->
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.  [ 2 posts ] 
Author Message
 Post subject: How to escape underscore in HQL
PostPosted: Thu Dec 17, 2009 5:11 pm 
Newbie

Joined: Fri Dec 05, 2008 6:58 pm
Posts: 7
I have a simple HQL query -

from Cat where name like '%a_2%'

where I want to match the underscore rather than using it as a wildcard (default SQL behavior with some databases).

I am not sure how to escape the '_'

I tried using

nameString.replaceAll("_", "\\_");

But this doesn't seem to work.
Also I am not using Hibernate criteria. I am using named parameters for HQL queries that I am constructing directly.

(The only other reference to this issue that I could find is - viewtopic.php?f=1&t=948181&p=2263772&hilit=escape+underscore+in+HQL#p2263772)

Help would be greatly appreciated.


Top
 Profile  
 
 Post subject: Re: How to escape underscore in HQL
PostPosted: Thu Dec 17, 2009 6:50 pm 
Newbie

Joined: Fri Dec 05, 2008 6:58 pm
Posts: 7
sorry this works. I had to add ESCAPE clause as well to my HQL string

i.e. something like -

from Cat where name like '%a@_b%' escape '@'

to get the desired results.


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