实际上,异常应该告诉你所需要的一切.在Restrictions.like你的情况是寻找一个整数,但有一个字符串作为参数.(你应该发布所用的确切电话Restrictions.like).
然而,有一种Restrictions.between方法.你可以用它来解决你的问题.例如:
criteria.add(Restrictions.between("year", 1960, 1970));
Run Code Online (Sandbox Code Playgroud)
还有其他方法.整数可以与Restrictions.le(小于或等于),Restrictions.lt(小于),Restrictions.gt(大于),Restrictions.ge(大于或等于)进行比较.
更好更快的解决方案是使用Criterion.sqlRestriction(String sql).您可以将sql形成为"to_char(year)like '19%'",请注意to_char是特定于数据库的.我不认为JPA支持to_char函数.