Skip to content

An association block inside or { } drops the rows without the association on Hibernate 5 and 7 #16924

Open

Description

@borinquenkid

An association block inside or { } drops the rows that have no such association, even when another branch of the or matches them.

TestEntity.withCriteria {
    or {
        child { eq('name', 'kid') }
        eq('name', 'orphan')
    }
}
// expected: the entity named 'with' (its child is 'kid') and the entity named 'orphan' (no child)
// actual on Hibernate 5 and Hibernate 7: only 'with'

The same happens for a to-many block (pets { eq('name', 'rex') } beside eq('firstName', 'Barney')): the person without pets is lost. eq('child', instance), isNull('child') and isNotNull('child') inside or are correct on every binding.

Measured with a shared TCK spec (CriteriaOrAssociationSpec, in the PRs linked below):

binding block in or
Hibernate 5 drops the rows without the association
Hibernate 7 same as Hibernate 5
Neo4j same until #16836, which fixes it
MongoDB UnsupportedOperationException: Join queries are not supported by MongoDB (by design)

So Hibernate 5 and 7 agree with each other and differ from what or means. Expected fix: the block has to be a left join (or an existence test) when it is under a disjunction. Not fixed here, because it changes results for existing queries and wants a decision.

Activity

  1. borinquenkid commented on Nov 11, 2026

    @borinquenkid
    MemberAuthor

    The GORM reference settles which behavior is intended. The criteria guide (Hibernate 5 and Hibernate 7, "Querying Associations") documents exactly this shape:

    def results = c.list {
        or {
            between('created', now - 10, now)
            transactions {
                between('date', now - 10, now)
            }
        }
    }

    and says: "Here we find all accounts that have either performed transactions in the last 10 days OR have been recently created in the last 10 days."

    An account created recently that has no transactions is therefore documented to be found. Hibernate 5 and 7 drop it, because the association block is an inner join. So this is a bug against the documented behavior, not a choice, and Neo4j's fix in #16836 matches the documentation.

    The docs are explicit that createAlias is an inner join by default and takes a join type argument, so that path is documented as inner. Only the block form inside or is documented as "either / or".

    Plan: fix the block-under-disjunction case on Hibernate 5 (7.0.x) and Hibernate 7 (8.0.x) with a left join, add the block cells (including to-many) to the shared TCK with Mongo excluded because it does not support association blocks, and leave the createAlias behavior unchanged.

  2. borinquenkid commented on Nov 11, 2026

    @borinquenkid
    MemberAuthor

    Fixes opened: #16930 (Hibernate 7, 8.0.x) and #16931 (Hibernate 5, 7.0.x). Neo4j is fixed by #16836.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions