We're updating the issue view to help you get more done. 

Bogus string replacement in SQLServer2005Dialect.insertRowNumberFunction()

Description

The fix for introduced a problem with column-names containing the character sequence 'from'.

For example, assume the string builder contains the following query before the call to SQLServer2005Dialect.insertRowNumberFunction() (formatted for better reading):

select persistent0_.rid as rid1688_,
persistent0_.deviationfromtarget as deviati16_1688_,
persistent0_.sortindex as sortindex1688_
from m_evalstate persistent0_
where persistent0_.customerid=?

After the call to SQLServer2005Dialect.insertRowNumberFunction(), the string builder contains:

select persistent0_.rid as rid1688_,
persistent0_.deviatio,
ROW_NUMBER() OVER (ORDER BY CURRENT_TIMESTAMP) as _hibernate_row_nrnfromtarget as deviati16_1688,
persistent0_.sortindex as sortindex1688_
from m_evalstate persistent0_
where persistent0_.customerid=?

But the intention of the fix was:

select persistent0_.rid as rid1688_,
persistent0_.deviationfromtarget as deviati16_1688_,
persistent0_.sortindex as sortindex1688_,
ROW_NUMBER() OVER (ORDER BY CURRENT_TIMESTAMP) as _hibernate_row_nr_
from m_evalstate persistent0_
where persistent0_.customerid=?

A fix would be the following code instead of the current:

final String myFrom = " " + FROM + " ";
int selectEndIndex = sql.indexOf( myFrom );
sql.insert( selectEndIndex, ", ROW_NUMBER() OVER (" + orderby + ") as _hibernate_row_nr_" );

Environment

Hibernate 4.0.0, SQLServer 2008R2

Status

Assignee

Lukasz Antoniak

Reporter

Fix versions

Labels

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

4.0.0.Final

Priority

Major