利用hibernate实现基本sql函数功能

最近接触的项目,访问数据库还是用的hibernate,好久没有使用hibernate了,有些基本用法已经忘记。
现在记录一下hibernate实现基本sql函数的语句,方便以后查找。

①创建Criteria,拼接查询条件

②实现sql函数
例如:

1、除去重复项 distinct :criteria.setProjection(Projections.distinct(Projections.property("entity定义的字段")));
2、取最大值 max :criteria.setProjection(Projections.max("entity定义的字段"));

criteria可以直接实现的sql函数如下:

猜你喜欢

转载自blog.csdn.net/qingdatiankong/article/details/81944815
今日推荐