| Author |
Escape HQL Like special characters
|
Sharon whipple
Ranch Hand
Joined: Jul 31, 2003
Posts: 294
|
|
Hi all
When executing HQL with like clause:
from Cat where name like “%” + myStr + “%”
For example in MSSQL escaping the % character will be:
Select * from cat where name like “%[%]%”
I think oracle will be:
Select * from cat where name like “%\%%”
How do I escape special characters?
Will hibernate escape characters for specific DB type?
Thank you
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
|
Use parameter binding.
|
JavaRanch FAQ HowToAskQuestionsOnJavaRanch
|
 |
Sharon whipple
Ranch Hand
Joined: Jul 31, 2003
Posts: 294
|
|
When running:
I am getting all rows from the table, instead of getting specific row containing % sign
Do i have to escape % character before calling setParameter?
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
|
Sorry - read your question too quickly. I think you can use the escape keyword, though I can't find this documented, though I did find this in the Hibernate forums.
|
 |
Sharon whipple
Ranch Hand
Joined: Jul 31, 2003
Posts: 294
|
|
Thank you for the link, Gavin stated that escape exist in Hibernate 3 (foo like <pattern> escape <escape-char>)
I am using older version of Hibernate...
Any other ideas?
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
|
I can't think how you would do this in Hibernate 2 without specifying an escape character. You may just have to introduce some database specific here unfortunately.
|
 |
 |
|
|
subject: Escape HQL Like special characters
|
|
|