When selectCase is passed to 'select' and 'groupBy' method simultaneously there is an error during criteria query compilation.
It was tested with PostgreSQL95Dialect, MySQL57Dialect and H2Dialect.
Only PostgreSQL95Dialect is affected.
SQL generated for prepare statements mechanism cannot be validated by postgres engine.
Directly from postgres console:
Error occurs due different methods of literal handling in 'select' and 'group by' query section.
Literals from 'select' case section are handled by:
but literals from 'group by' case section are handled by:
Postgres intreprets that if in the same case section in 'select' and 'group by' are different values (e.g. 'child' and $1) it is not valid query (it needs two same values or literals there e.g. $1 and $1 or 'child' and 'child').
There is a workaround if org.hibernate.query.criteria.LiteralHandlingMode#INLINE is set then generated query is valid.
The org.hibernate.query.criteria.LiteralHandlingMode.INLINE mode will inline literal values as-is. To prevent SQL injection, never use org.hibernate.query.criteria.LiteralHandlingMode.INLINE with String variables.
I also tried to use named parameters in selectCase but there I get other error.
Windows 10 Pro