hi all,
Ive searched the forums and JIRA and haven't found a report about this, so here it goes,
we have migrated a spring 2.5, Mysql 5.6 webapp from Hibernate 3.2.5GA to 3.6.1Final.
When we try to run a criteria query with countDistinct we get a Invalid SQL Syntax error:
Criteria criteria = session.createCriteria(example.class).setProjection(Projections.countDistinct("examplefield"));
The SQL generated is along the lines of:
select count(distinct, this_.examplefield) as y0_ from example this_
as you can see, there is a ',' char between the reserverd keyword distinct and the column.
Looking at the source (3.6.1 and upwards to latest), the sql is generated in the "render" method from class org.hibernate.dialect.function.StandardSQLFunction:
Code:
public String render(Type firstArgumentType, List arguments, SessionFactoryImplementor sessionFactory) {
StringBuffer buf = new StringBuffer();
buf.append( name ).append( '(' );
for ( int i = 0; i < arguments.size(); i++ ) {
buf.append( arguments.get( i ) );
if ( i < arguments.size() - 1 ) {
buf.append( ", " );
}
}
return buf.append( ')' ).toString();
}
given that CountProjection class passes render an array with the keyword distinct and the columns, this results in the faulty SQL.
I would like to open a JIRA with this, but I dont know how :/ anyway, thanks for any input on this!