Hibernate version: 3.2.5.ga
Name and version of the database you are using: Postgres 8.3
Code:
"from Tag t order by rand()"
works fine when run against hsqldb but fails against postgres. I've turned on hibernate logging and the generated sql ends with "order by rand()" in both cases, however postgres doesn't have a rand() function - it uses random() instead.
The PostgresSQLDialect class contains the line
Code:
registerFunction( "random", new NoArgSQLFunction("random", Hibernate.DOUBLE) );
I'm not 100% sure how the dialects work, but suspect this should be
Code:
registerFunction( "rand", new NoArgSQLFunction("random", Hibernate.DOUBLE) );
Certainly when I extend the dialect as follows my hql statement works in both hsqldb and postgres environments.
Code:
class CustomPostgresSQLDialect extends PostgreSQLDialect {
CustomPostgresSQLDialect() {
super()
registerFunction( "rand", new NoArgSQLFunction("random", Hibernate.DOUBLE) );
}
}
Is this a bug or am I doing something daft?