如何在HQL或JPQL中使用强制转换?

问题描述 投票:0回答:1

嗨,我的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();\
 In the above query ,I have tried to cast showdatetime as date and sum the gross collection according to date.BUt cast is not supporting

在hql中,我不想使用本机查询。

java sql hibernate spring-boot jpql
1个回答
0
投票

HQL中支持[CAST,因为基础DB支持它。

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

See:1. HQL Expressions

© www.soinside.com 2019 - 2024. All rights reserved.