Search code examples
hibernatehql

Does HQL have an equivalent to SQL COVERT() function


I am adapting our SQL queries to hql but ran into a roadblock when one of our queries makes use of a CONVERT() function. I can't find anything about it for hql on the net.

Query:

"SELECT tse.id, tse.ts_entries_ParentID As ParentID, tse.hours, 

                            tse.project As projectID, (SELECT CONCAT(Project_Pastel_Prefix, ' - ', Project_Description) FROM Project WHERE Project_Code = tse.project) As 'projectName',
                            tse.task As taskID, (SELECT Budget FROM TimesheetCategories WHERE id = tse.task) As 'taskName',
                            tse.task As oldTaskID, (SELECT name FROM ts_tasks WHERE id = tse.task) As 'oldTaskName',

                            IF(STRCMP(tse.comment,'') = 0, (SELECT CONCAT(Project_Pastel_Prefix, ' - ', Project_Description) FROM Project WHERE Project_Code = tse.project), tse.comment) As 'text', 
                            tse.user As userID, tse.customer As customerID,
                            concat(tsw.ts_working_hours_Date, ' ',tsw.ts_working_hours_Time_Start) As startDate, concat(tsw.ts_working_hours_Date, ' ',tsw.ts_working_hours_Time_End) As endDate,
                            CONVERT(1, UNSIGNED) As TypeId,
                            if(tsw.ts_working_hours_Date BETWEEN '1994-01-01' AND '2018-03-31', 2, 1) as TemplateID,

                            0 AS 'days',
                            0 AS 'isDoc',
                            '0' AS 'authorised',
                            tse.comment AS 'description',
                            0 AS 'leaveType',
                            0 AS 'isApproved'

                            FROM ts_entries tse, ts_working_hours tsw
                            WHERE tse.ts_entries_ParentID = tsw.ts_working_hours_ID
                            AND tse.user = :userID
                            AND tsw.ts_working_hours_Date BETWEEN ':startDate' AND ':endDate'

Solution

  • You could use cast function as

    cast(1 as UNSIGNED)