Hibernate Projections.countDistinct(String PropertyName) is not working as expected.
I am trying to do distinct column on count using Hibernate Criteria and it fails with org.hibernate.exception.SQLGrammarException.
ERROR | 2014-06-25 13:29:48,076 | http-localhost/127.0.0.1:8080-1 | | dao.DAOThrowsAdvice | DAOThrowsAdvice.afterThrowing(...) is reporting this error which occurred in the data access layer:could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet at org.springframework.orm.hibernate4.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:144) at org.springframework.orm.hibernate4.HibernateTemplate.doExecute(HibernateTemplate.java:343) at org.springframework.orm.hibernate4.HibernateTemplate.execute(HibernateTemplate.java:295) .......... Caused by: org.hibernate.exception.SQLGrammarException: could not extract ResultSet at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:123) at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49) at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:124) at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:109) at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:88) at org.hibernate.loader.Loader.getResultSet(Loader.java:2062) at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1859) at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1838) at org.hibernate.loader.Loader.doQuery(Loader.java:906) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:348) at org.hibernate.loader.Loader.doList(Loader.java:2550) at org.hibernate.loader.Loader.doList(Loader.java:2536) at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2366) at org.hibernate.loader.Loader.list(Loader.java:2361) at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:124) at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1587) at org.hibernate.internal.CriteriaImpl.list(CriteriaImpl.java:374) at org.hibernate.internal.CriteriaImpl.uniqueResult(CriteriaImpl.java:396) at com.crsoftwareinc.crs.core.dao.PagingHibernateCallback.doRowCount(PagingHibernateCallback.java:210) at com.crsoftwareinc.crs.core.dao.PagingHibernateCallback.doInHibernate(PagingHibernateCallback.java:104) at org.springframework.orm.hibernate4.HibernateTemplate.doExecute(HibernateTemplate.java:340) ... 129 more Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near ','. at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:196) at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1454) at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(SQLServerPreparedStatement.java:388) at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(SQLServerPreparedStatement.java:338) at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:4026) at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1416) at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:185) at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:160) at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeQuery(SQLServerPreparedStatement.java:281) at sun.reflect.GeneratedMethodAccessor126.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at com.p6spy.engine.logging.P6LogPreparedStatementExecuteDelegate.invoke(P6LogPreparedStatementExecuteDelegate.java:42) at com.p6spy.engine.proxy.GenericInvocationHandler.invoke(GenericInvocationHandler.java:103) at org.p6spy.$java.sql.Statement$$EnhancerByCGLIB$$ee8e2699.executeQuery(<generated>) at org.jboss.jca.adapters.jdbc.CachedPreparedStatement.executeQuery(CachedPreparedStatement.java:107) at org.jboss.jca.adapters.jdbc.WrappedPreparedStatement.executeQuery(WrappedPreparedStatement.java:462) at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:79)
|