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

Abierto
#16,889 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
25/100
Tipo de issue
Nueva funcionalidad
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
groovy

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Groovy
Estrellas
2.9k
Forks
980
Merge medio
2 d 4 h
PR fusionados (30 d)
130

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de apache/grails-core

Todos los issues de apache/grails-core

Issues similares

Más issues de Backend & API Design

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.