使用hibernate和informix从datetime转换为date

时间:2013-06-12 12:20:30

标签: java hibernate informix

我在Hibernate中遇到'cast'expresion问题, 当我执行下一个HQL时:

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将其翻译成这个SQL:

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

我收到了这个错误:

A syntax error has occurred.
org.hibernate.exception.SQLGrammarException: could not execute query

因为它正在解析像'cast(auditanota0_.dataauditasdate)'这样的演员表 而不是'cast(auditanota0_.dataaudit as date)'

我正在使用org.hibernate.dialect.InformixDialect,那有什么不对?

你可以帮帮我吗?请。 谢谢。

0 个答案:

没有答案