code_junkie

Configure Hibernate to escape underscores in LIKE clause using SQL Server dialect

Nov 12th, 2011
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. SELECT * FROM my_table WHERE name LIKE '_H9%';
  2.  
  3. public class EscapingLikeExpression extends LikeExpression {
  4. public EscapingLikeExpression(String propertyName, String value) {
  5. super(propertyName, escapeString(value), '!', false);
  6. }
  7.  
  8. static String escapeString(String inputString) {
  9. inputString = inputString.replace("_", "!_");
  10. return inputString;
  11. }
  12.  
  13. }
  14.  
  15. inputString = inputString.replace("!", "!!");
Add Comment
Please, Sign In to add comment