例如表 student 中的createTime字段
,使用SQL语句可以使用直接select * from student where createTime like ‘%2015-10%’,
转换成hql也没有问题,但是使用Criteria对象查询的话会出现string和date类型不匹配的错误!
Restrictions.like(“createTine”,"%"+searchStr+"%")这句在date类型中不能使用,此时我们将语句转换成Restrictions.SqlRestriction(“createTime like ‘%+seatchStr+%’”)。注意了:这里的createTime字段并不是对应的实体字段名称,而是数据库字段名称
参考文章:https://blog.csdn.net/u010699122/article/details/49098543?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522162150002316780262542744%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=162150002316780262542744&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2allfirst_rank_v2~rank_v29-10-49098543.first_rank_v2_pc_rank_v29&utm_term=hibernate%E6%9F%A5%E8%AF%A2date%E5%AD%97%E6%AE%B5&spm=1018.2226.3001.4187