问题情景:

   在联表查询时

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

    ```

// 两张表关联查询

Join<Project, Plan> planJoin =
root.join("plans", JoinType.LEFT);
predicates.add(cb.equal(
planJoin.get(ColumnConsts.SUPPLIER_ID), subjectId));
query.groupBy("id");
```
查询结果数据正确,TotalElements数量偏大。

追查源码到统计totalElement,是统计结果集的所有记录
```
private static long executeCountQuery(TypedQuery<Long> query) {

Assert.notNull(query, "TypedQuery must not be null!");

List<Long> totals = query.getResultList();
long total = 0L;

for (Long element : totals) {
total += element == null ? 0 : element;
}

return total;
}
```
解决办法:将
```
query.groupBy("id");
//换成
query.distinct(true);  
//去除重复数据即可
```
 参考文章:https://blog.csdn.net/huwentao_totti/article/details/81389882
扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄