Hibernate Criteria API condition “like” with integer
问题 In my database I have a column "year" which is an integer. How can I search by using Criteria API (not by HQL) which records contain, for example "196..." in the year column? I think it should be Restrictions.like , but I got exception: SEVERE: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer 回答1: a better and faster solution would be to use Criterion.sqlRestriction(String sql). You can form the sql as, "to_char(year) like '19%'", be aware that to_char is