Skip to content

Generating countQuery for queries with CTE fails with actual pagination #3726

Closed
@bountin

Description

@bountin

I rechecked the "Automatic countQuery with CTE" case from #3504 and found another adjacent issue. In the other bug report I've used Pageable.unpaged() which apparently doesn't actually execute a count because the query itself already returns all elements. I've updated the repository with a constrained page request and now I have another exception from Hibernate not accepting the generated query:

org.hibernate.query.SemanticException: The derived SqmFrom[id, number] can not be used in a context where the expression needs to be expanded to identifying parts, because a derived model part does not have identifying parts. Replace uses of the root with paths instead e.g. `derivedRoot.get("alias1")` or `derivedRoot.alias1`

The generated countQuery is WITH entities AS (SELECT e.id as id, e.number as number FROM TestEntity e) SELECT count(c) FROM entities c.

See again here: https://github.com/bountin/spring-data-jpa-issue-3504

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions