小弟刚从mybatis转到hibernate,遇到了不少坑,在这里不定期更新。以告慰相同处境的亲。
1、首先hibernate的HQL语法有很多坑,有些在SQL中能执行的语句,在HQL中未必能执行,比如HQL就不支持union操作,可以考虑把你要union的两个查询分开写,然后将结果合起来,传到你要使用union的地方。
2、其次,注意mysql数据库与SqlServer、oracle数据库存在差别的,虽然SQL语法大体差不多,但是在细小的地方还是不同。
比如:MySQL不支持,在增删操作语句中嵌套本表的查询子语句。
delete from table where id in(select id from table where id >10);//会报错啊,兄弟们,提示mysql不支持自身子嵌套。
修改成:
delete from table where id in(select id from (select id from table where id >10) as A);//成功。
3、对于Spring boot+JPA的复杂查询,需要进行如下配置才可以。不然会报如下错误:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'mainApi': Unsatisfied dependency expressed through field 'checkProductStatusService |