Hi I have some problem with group by a result of a custom function in Hibernate. The query looks like:
@Query("SELECT NEW ReportDay(" +
"FUNCTION('atTimezone', p.startDate, :timezone), "
"SUM(p.energy)) " +
"FROM Process p GROUP BY FUNCTION('atTimezone', p.startDate, :timezone)")
The error thrown is that p.startDate must appear in groupBy clause or in an aggregate function. But the custom function is in the group by clause.
Any ideas? The custom function is this:
registerFunction("atTimezone", new SQLFunctionTemplate(StandardBasicTypes.TIMESTAMP,"date_trunc('day', (cast(?1 as timestamp) AT TIME ZONE cast(?2 as varchar)))"));
and is trying to get the date trunc to day in a specific timezone. many thanks!