如何在hql或jpql中使用cast?

piwo6bdm  于 2021-07-26  发布在  Java
关注(0)|答案(1)|浏览(377)

嗨,我的hql查询是这样的。

@Query("select A.TheaterName as theater,A.MovieName as movie,CAST(A.ShowDateTime as showDate)" +
         "(select sum(TicketPrice) from ccmsfdb2.HallApi.TicketTransaction where \n" +
         "CAST(ShowDateTime as date)=CAST(A.ShowDateTime as Date) AND\n" +
         " MovieName=A.MovieName and TheaterName=A.TheaterName and TicketStatusValue=1) as collection\n" +
         "from CCMSFDB2.HallApi.TicketTransaction A where A.MovieName='Sanju'  \n" +
         "and A.TheaterName='QFX Jai Nepal' \n" +
         "group by CAST(A.ShowDateTime as date),A.TheaterName,A.MovieName,CAST(A.ShowDateTime as Date)   order by showDate DESC")
    List<MovieCollectionAccordingToTheaaterDto> getMovieCollectionAccordingToTheater();\

在上面的查询中,我尝试将showdatetime转换为date,并根据date对总集合求和,但hql不支持转换,我不想使用本机查询。

6uxekuva

6uxekuva1#

CAST 在hql中受支持,前提是底层数据库支持它。
尝试日期的完全限定类名( java.util.Date )内部 @Query 表情。
请参见:
1.hql表达式

相关问题