I have a query that uses the function to_char(). I know it's not standard, but I can't figure out how to sort by year/month in reporting queries. This is the query I'm trying to use. Actually, the sql that it generates is valid as it works in my database admin tool (phpPgAdmin) for postgres 7.5.
Code:
Query query = session.createQuery(
"select new com.upfactor.rns.resource.hibernate.report.TransactionCount( " +
" to_char(history.date, 'YYYY-MM'), count(distinct rnsTransaction), count(history) ) " +
"from Administrator administrator " +
" inner join administrator.businesses business " +
" inner join administrator.persons person " +
" inner join business.rnsTransactions rnsTransaction " +
" inner join rnsTransaction.histories history " +
"where " +
" business.id = :businessId and " +
" person.id = :personId " +
"group by to_char(history.date, 'YYYY-MM')"
);
Here is the postgres equivalent that does work:
Code:
select to_char(histories5_.date , 'YYYY-MM'), count(distinct rnstransac4_.id) as x0_0_, count(histories5_.id) as x1_0_ from administrator administra0_ inner join business businesses1_ on administra0_.id=businesses1_.administrator_id inner join administrator_to_person persons2_ on administra0_.id=persons2_.administrator_id inner join person person3_ on persons2_.person_id=person3_.id inner join rns_transaction rnstransac4_ on businesses1_.id=rnstransac4_.business_id inner join rns_transaction_history histories5_ on rnstransac4_.id=histories5_.rns_transaction_id where (businesses1_.id=2 ) group by to_char(histories5_.date , 'YYYY-MM')
Anyway to tell hibernate that to_char() is okay?