With this question, you want to avoid needing to write a unique query because the query would need to differ across multiple databases. Only using hibernate criteria, you want to have the ability to escape special figures.

This case 's the reason for requiring a chance to escape special figures:

Think that we now have table 'foo' within the database. Table 'foo' consists of only one area, known as 'name'. The 'name' area can contain figures that might be considered special inside a database. Two good examples of these a title are 'name_1' and 'name%1'. Both '_' and '%' are special figures, a minimum of in Oracle. If your user wants to find one of these simple good examples once they are joined within the database, problems may occur.

criterion = Restrictions.ilike("name", searchValue, MatchMode.ANYWHERE);
return findByCriteria(null, criterion);

Within this code, 'searchValue' may be the value the user has because of the application for its search. When the user wants to find '%', the consumer will probably be came back with every 'foo' entry within the database. The reason being the '%' character signifies the "a variety of figures" wildcard for string matching and also the SQL code that hibernate produces may be like:

select * from foo where name like '%' 

It is possible to method to tell hibernate to flee certain figures, or to produce a workaround that's not database type specific?