File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed
ebean-core/src/main/java/io/ebeaninternal/server/query
ebean-test/src/test/java/org/tests/query Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -242,7 +242,7 @@ <T> CQueryRowCount buildRowCountQuery(OrmQueryRequest<T> request) {
242242 boolean withAgg = false ;
243243 if (!countDistinct ) {
244244 withAgg = includesAggregation (request , query );
245- if (!withAgg ) {
245+ if (!withAgg && request . descriptor (). hasId () ) {
246246 // minimise select clause for standard count
247247 query .setSelectId ();
248248 useColumnAlias = false ;
Original file line number Diff line number Diff line change 88import org .tests .model .basic .Customer ;
99import org .tests .model .basic .Order ;
1010import org .tests .model .basic .ResetBasicData ;
11+ import org .tests .model .noid .NoIdBean ;
1112
1213import java .util .List ;
1314
@@ -101,4 +102,27 @@ void find_count_distinct_multiplePropertiesSameColumn() {
101102 assertThat (count ).isGreaterThan (0 );
102103 }
103104
105+ @ Test
106+ void find_count_noIdProperty () {
107+ LoggedSql .start ();
108+
109+ DB .find (NoIdBean .class )
110+ .select ("name, subject" )
111+ .findCount ();
112+
113+ DB .find (NoIdBean .class )
114+ .setDistinct (true )
115+ .select ("name, subject" )
116+ .findCount ();
117+
118+ List <String > sql = LoggedSql .stop ();
119+
120+ assertThat (sql .get (0 )).contains ("select count(*) from noidbean t0" );
121+ if (isSqlServer () || isH2 () || isMariaDB () || isMySql ()) {
122+ assertThat (sql .get (1 )).contains ("select count(*) from ( select distinct t0.name c0, t0.subject c1 from noidbean t0)" );
123+ } else {
124+ assertThat (sql .get (1 )).contains ("select count(*) from ( select distinct t0.name, t0.subject from noidbean t0)" );
125+ }
126+ }
127+
104128}
You can’t perform that action at this time.
0 commit comments