SelectCase does not work when simultaneously exists in select and group by sections

Description

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 response:

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.

but

from AvailableSettings#CRITERIA_LITERAL_HANDLING_MODE

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.

Environment

hibernate-orm 5.2.12
Postgres 9.5
Windows 10 Pro

Assignee

Unassigned

Reporter

Adrian Łukawski

Fix versions

Labels

backPortable

None

Suitable for new contributors

None

Requires Release Note

Affirmative

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure