And just by the way, you can replace the count function so you could alter the sql to whatever you like. In your dialects constructor do
registerFunction("count", new MyCountFunction());
The implementation of the count function can be based on the existing implementation
org.hibernate.dialect.function.StandardAnsiSqlAggregationFunctions.CountFunction