Hibernate 7: do repeated blocks of one association share a join, or does each block get its own?

Aperta
#16,889 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
25/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
groovy

Direzione di ricerca

Start with AssociationBlockJoinDecisionSpec, then compare the two test groups enabled by ALIAS_BLOCK_DECISION=shared and per-block. Read the related behavior and tests in #16773 and #16863, especially AssociationSortSpec, to understand the competing join and ordering rules. The work is complete when one rule is chosen, its tests define the contract, and the other test group is removed.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

The question

When a criteria query names the same association in more than one block, does each block get its own join, or do they all share one?

Pet.withCriteria {
    owner { scores { eq('round', 'first') } }
    owner { scores { eq('round', 'second') } }
}

An owner has one score in each round. If the two scores blocks share a join, one score has to be in both rounds and no pet matches. If each block is its own scope, the pet of an owner with a score in each round matches.

What each version does today
Query Hibernate 5 Hibernate 7 on 8.0.x Hibernate 7 with #16773
the query above no rows the pet of the owner with both rounds no rows
one owner block that contains both scores blocks no rows no rows no rows
two top-level likes blocks, x then y no rows no rows no rows

Hibernate 5 and #16773 share the join. 8.0.x shares it for repeated blocks at the top level and inside one block, but not for a nested block under a repeated parent block, which looks like a side effect of how blocks are translated and not a rule. #16863 has tests that assert that result, six test cases in AssociationSortSpec.

A second question comes with it. When an association has several aliases or blocks, which join does an order by the path (order('scores.score')) sort by: the join of the first alias, as #16773 documents, or the join of the block the order is in, as #16863 asserts?

Why this is open

Hibernate 5 is not a reliable reference for this. Its rows for nested blocks depend on the order of the steps and on whether the criteria runs at the top or in a subquery, so it can only be one input. Both answers can be built on JPA. Each one changes the rows of an existing kind of query.

What is in place

AssociationBlockJoinDecisionSpec holds both answers as tests, each switched off until this is decided. The environment variable ALIAS_BLOCK_DECISION set to shared or per-block turns one group on, so either can be tried locally. Once decided, the chosen group becomes the contract and the other is deleted.

Related: #16773, #16863, #16866, #16851.

Lingua principale
Groovy
Stelle
2.9k
Fork
980
Merge medio
2g 4h
PR unite (30g)
130

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di apache/grails-core

Tutte le issue di apache/grails-core

Issue simili

Altre issue su Backend & API Design

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.