Hibernate & Paging: BROKEN when a column contains the word "FROM"

Description

When paging is enabled, Hibernate inserts the following SQL as the LAST column in the SELECT statement:

, ROW_NUMBER() OVER (ORDER BY CURRENT_TIMESTAMP) as _hibernate_row_nr_

It appears Hibernate does this by searching for the word "FROM" and inserting before it.

However, if there exists a COLUMN with the word "FROM" in it, Hibernate inserts in the WRONG place, causing the following error message from SQL Server:

Incorrect syntax near the keyword 'as'.

To fix: look for the last occurrence of the word "FROM", not the first.

I will put together a Test project and attach at a later time.

Environment

Mac OS X 10.7. JBoss AS 7.1.1. Hibernate 4.1.3. Microsoft SQLJDBC 4.0. Microsoft SQL Server 2008.

Status

Assignee

Lukasz Antoniak

Reporter

Kuthair Habboush

Fix versions

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure