Skip to content

Count query derivation from DISTINCT queries seems to be broken #3269

Closed
@da-z

Description

@da-z

I have a large chunk of JPA code that was working fine in Spring Boot 2.x but not in Spring Boot 3.x (Hibernate 6 on Oracle and H2 in Oracle mode in tests):

Sample JPQL query:

SELECT DISTINCT abc AS x FROM T -- (note the AS alias)

In SB 3.x I am getting the error: At 1:n and token 'AS', no viable alternative at input 'SELECT count(DISTINCT abc *AS x

And indeed, that's not a valid SQL query because aliases are not allowed in that scenario.

My take on this is: either strip the alias, or derive the Count query like this, which means you don't need to mess with the original query:

SELECT COUNT(*) FROM ({original_sql}) -- I assume this is how it is working in SB 2.x

Metadata

Metadata

Labels

type: regressionA regression from a previous release

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions