嗨,我的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转换为日期,并根据日期求和总计集合,但hql不支持强制转换,我也不想使用本机查询。

最佳答案

HQL支持CAST,因为底层数据库支持它。

尝试在java.util.Date表达式内使用Date(@Query)的全限定类名。

见:
1. HQL Expressions

10-08 16:19