-->
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: Escaping special sql characters using criteria
PostPosted: Mon May 23, 2016 5:48 am 
Newbie

Joined: Tue Nov 17, 2015 11:53 am
Posts: 4
Hi All,

I'm facing a non usual issue while using criterias I want to do a criteria with a like clause but the text contains special chars like the bracket char "[" and it seems that it's a special char in MSSQL database.

From an sql query I must use the special wording ESCAPE see example : AND file1.FILE_NAME like '%[Main profile picture]%' ESCAPE '['

But I dont know how I can do the same using criteria I'm currently using this clause criteria.add(Restrictions.like("files.fileName", "%Main profile picture%")); but that's not what I want I really need to escape the '[' char.

Can somebody help me in this please...?

Thank you for your help!


Top
 Profile  
 
 Post subject: Re: Escaping special sql characters using criteria
PostPosted: Mon May 23, 2016 9:08 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
You can try it like this:

Code:
criteria.add(Restrictions.like("files.fileName", "%[[]Main profile picture]%"));


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.