Closed masankin closed 3 years ago
问题说明: fenix/src/main/java/com/blinkfox/fenix/jpa/FenixJpaQuery.java 中 this.sqlInfo.getSql().replaceFirst(REGX_SELECT_FROM, SELECT_COUNT);
如果 this.sqlInfo.getSql() 查询为: select distinct t.id from t_user
会被替换成 select count(*) as count from t_user
这样导致 list 集合数据 和 count 总数不一样
正确替换sql应该为: select count(distinct t.id) as count from t_user
解决方案: 1.count查询 正则支持识别 distinct: 2.或者提供一个方法/注解属性,类似 countQuery ,能够手动控制是否使用 distinct
目前解决方法是用 countQuery 查询总数
@masankin 后续可以考虑支持,使用解决方案2 较为合适。
@masankin @blinkfox 根据你们的讨论,我试着做了一版:https://github.com/blinkfox/fenix/pull/24
@masankin 请问你们使用的fenix和jpa版本是多少呢?
这个 issue 新版本有了,我就关了哈
问题说明: fenix/src/main/java/com/blinkfox/fenix/jpa/FenixJpaQuery.java 中 this.sqlInfo.getSql().replaceFirst(REGX_SELECT_FROM, SELECT_COUNT);
如果 this.sqlInfo.getSql() 查询为: select distinct t.id from t_user
会被替换成 select count(*) as count from t_user
这样导致 list 集合数据 和 count 总数不一样
正确替换sql应该为: select count(distinct t.id) as count from t_user
解决方案: 1.count查询 正则支持识别 distinct: 2.或者提供一个方法/注解属性,类似 countQuery ,能够手动控制是否使用 distinct
目前解决方法是用 countQuery 查询总数