The query is generated with a comma after distinct keyword which is not expected.
Code snippet setting the projection : criteria final Integer result = (Integer) this . getHibernateTemplate() .executeWithNativeSession(new HibernateCallback<Object>() {
public Object doInHibernate(final Session session) {
Criteria criteria1 = session .createCriteria(TimeReminderResultDTO.class);
criteria1. setProjection(Projections.countDistinct("id")); final Object result Integer totalRecs = criteria .setMaxResults ( 2 (Integer ) criteria1 . setFirstResult(0). uniqueResult() ) ;
return totalRecs; } });
Query generated: SELECT TOP (2) select count( DISTINCT distinct , this_. tbl_id id ) AS as y0_ FROM from tbl this_ WHERE this_.tbl_id2 IN (SELECT tbl.tbl_id2 FROM tbl INNER JOIN tbl2 ON tbl2.tbl2_id = tbl.tbl_id2 WHERE tbl2.tbl2_flg = 'Y' AND tbl2.tbl2_nm = 'abc')
|