Search code examples
postgresqlhibernatespring-data-jpahql

unexpected token: :(colon) in Hibernate


I'm trying to do the following code, but i get the unexpected token: : near line 1 error which refer to ord.date_out::date. Here is my code

@Query(value="select new com.ameerarestapi.wrapper.report.SummaryPeriodicSales(sto.name, sum(odi.subtotal_price), sum(odi.qty), ((sum(odi.subtotal_price))/(sum(odi.qty))), ord.date_out::date) "
                 + "from OrderDetailItem odi "
                 + "left join odi.order as ord "
                 + "left join ord.store as sto "
                 + "where ord.store.principle = :principle and ord.orderStatus IN :orderstatus and ord.dateOut between :date1 and :date2 and ord.voidStatus = :voidStatus "
                 + "group by sto.name, ord.date_out::date ")
List<SummaryPeriodicSales> getReportDaily(@Param("principle") Principle principle,@Param("orderstatus") List<OrderStatus> orderstatus,@Param("date1") Date date1,@Param("date2") Date date2,@Param("voidStatus") byte voidStatus);

I'm using postgre database


Solution

  • Use the standard CAST() operator instead:

    CAST(ord.date_out AS date)