Skip to content

Hibernate 7: split HqlQueryContext into HqlText, QueryParameters and QuerySettings #16616

Closed

Description

@borinquenkid

Summary

HqlQueryContext (GORM for Hibernate 7) is a record that also holds the HQL scanner, the query rewriting and the parameter handling. Split it into small classes once the Groovy conversion of the module has landed.

Why

PR #16597 fixes HQL queries with a subquery being rewritten into invalid HQL. The defect came from a text scanner living next to parameter handling: indexOf("select ") and indexOf(" from ") were repeated in four methods, each with its own idea of where the query itself starts. #16597 puts the search in two helpers, but they are still private static methods of the same record, and every method still lowercases and rescans the string.

Proposal

  • HqlText (or HqlStatement): the HQL string and everything that reads it: the top-level select/from search (outside parentheses, string literals, quoted identifiers and comments), normalizeNonAliasedSelect, getRootAlias, countHqlProjections, getSingleProjectionClause and the result type. The positions are found once.
  • QueryParameters: the named and positional parameters, the expansion of a GString, and convertValue.
  • QuerySettings: the settings map and the hints, with the AvailableHints filter inside the class.
  • HqlQueryContext: a thin record of the three, the target class and the isUpdate/isNative flags.

No change of behavior. HqlQueryContextSpec and HibernateGormStaticApiSpec stay as they are and are the safety net; add small specs for HqlText and QueryParameters, including a leading with clause, names that contain select, and escaped quotes.

Order

  1. Hibernate 7: keep HQL queries with a subquery intact #16597 lands on 8.0.x.
  2. refactor: convert the grails-data-hibernate7 modules to Groovy #16572 converts the module to Groovy.
  3. This refactor, on 9.0.x, as its own pull request, so that it is not read as part of a mechanical language conversion.

Activity

  1. borinquenkid commented on Oct 22, 2026

    @borinquenkid
    MemberAuthor

    Order change: the review of #16719 asks for HqlText to start there, on 8.0.x, with the root-query unwrapping and the union-branch case from #16712 as its first spec rows. #16572 then carries the split up in its merge-up. QueryParameters and QuerySettings stay as separate follow-ups.

  2. borinquenkid commented on Oct 22, 2026

    @borinquenkid
    MemberAuthor

    Step 0, before HqlText: a shared SqlText scanner on 8.0.x (branch feat/sql-text-8.0.x, with the fix for #16717), so that HqlQueryContext, SqlProjection and SqlRestriction stop carrying their own quote and comment rules. HqlText then builds on it.

  3. borinquenkid commented on Oct 22, 2026

    @borinquenkid
    MemberAuthor

    Steps 0 and 1 are in #16735: SqlText (one scanner, one read per text) and HqlText (one reading per HQL query, used by HqlQueryContext.prepare), plus HqlKeyword. Left for a follow-up: QueryParameters and QuerySettings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions