Register postgres random() function as "rand" in PostgresSQLDialect

Description

I have an HQL query which uses "order by rand()". This works fine in our local integration tests (which are run against hsqldb), but fails against our build integration tests which runs postgres.
The reason the query fails is because postgres function for "rand" is called "random". We can workaround this by dynamically detecting the db driver and generating db specific queries, but it strikes me that the cleanest solution for this is to simply re-register postgres' random function as "rand" in the PostgresSQLDialect, i.e.

registerFunction( "random", new NoArgSQLFunction("random", Hibernate.DOUBLE) );
registerFunction( "rand", new NoArgSQLFunction("random", Hibernate.DOUBLE) );

Environment

Postgres 8.3

Activity

Show:
Grep Sed
March 30, 2012, 5:40 AM

I'm surprised that this simple bug hasn't got fixed after 3.5 years.

Brett Meyer
January 4, 2013, 12:29 AM

, "simple bugs" are a great way to contribute to Hibernate with pull requests

Brett Meyer
January 4, 2013, 12:39 AM

Thanks to for the pull request!

Fixed

Assignee

Brett Meyer

Reporter

Stephen Cresswell

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Trivial