I have a problem with the 'cast' expresion in Hibernate, when I execute the next HQL:
Code:
SELECT new es.xunta.surex.vo.informes.ActividadUsuarioAuxVO(usu.codusu, cast(au.dataaudit as date), fun.idfunaudit, count(*))
FROM AuditAnotacion au, FunAuditoria fun, Usuario usu
WHERE au.funAuditoria.idfunaudit=fun.idfunaudit
AND au.usuario.idusu=usu.idusu
AND usu.unidade.iduni=:iduni
AND au.dataaudit between :desde AND :hasta
GROUP BY 1, 2, 3
ORDER BY 1, 2, 3
Hibernate 'translates' it into this SQL:
Code:
select
usuario2_.codusu as col_0_0_,
cast(auditanota0_.dataauditasdate) as col_1_0_,
funauditor1_.idfunaudit as col_2_0_,
count(*) as col_3_0_
from
audit_anotacion auditanota0_,
fun_auditoria funauditor1_,
usuario usuario2_
where
(
auditanota0_.idfunaudit=funauditor1_.idfunaudit
)
AND(
auditanota0_.idusu=usuario2_.idusu
)
AND(
usuario2_.iduni=?
)
AND(
auditanota0_.dataaudit between ? AND ?
)
group by
1 ,
2 ,
3
order by
1 ,
2 ,
3
And I get this error:
Quote:
A syntax error has occurred.
org.hibernate.exception.SQLGrammarException: could not execute query
Because It's parsing the cast like this 'cast(auditanota0_.dataauditasdate)' instead of 'cast(auditanota0_.dataaudit as date)'
I'm using org.hibernate.dialect.InformixDialect, so what's wrong?
Could you help me? Please. Thank you.