Issue Type: Bug Bug
Affects Versions: 4.1.8
Assignee: Unassigned
Components: query-hql
Created: 12/Nov/12 5:26 AM
Description:

Using setFirstResult (for paging) when CAST is used in HQL generates invalid SQL.
The AS part of the CAST command is treated as if it were an alias and the whole part right to it is treated as the column name i.e. "varchar(255)) as col_0_0_" instead of "col_0_0_"

SQL server then responds with:
'varchar' is not a recognized built-in function name

JPQL query:
SELECT
NEW DocumentResults
(
CAST(dok.brojDokumenta AS string) AS dokument
,dok.dokumentiID
)
FROM
pos.LC302_Dokumenti dok

Generated Hibernate query:
WITH query AS (
SELECT
inner_query.*,
ROW_NUMBER() OVER (ORDER BY CURRENT_TIMESTAMP) as _hibernate_row_nr_
FROM (
select TOP
cast(lc302_doku6_.redniBrojStavke as varchar(255)) as col_0_0_,
lc302_doku6_.dokumentiID as col_1_0_
from
LC302_Dokumenti lc302_doku6_
order by
lc302_doku6_.dokumentiID DESC ) inner_query )
SELECT
varchar(255)) as col_0_0_,
col_1_0_
FROM
query
WHERE
_hibernate_row_nr_ >= ?
AND _hibernate_row_nr_ < ?

With Hibernate 4.0.1 everything works correctly.

Environment: Hibernate 4.1.8.Final, MSSQL 2008R2, SQLServer2008Dialect
Project: Hibernate ORM
Labels: HQL
Priority: Critical Critical
Reporter: Vedran Mikulcic
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira