Skip to content

where {} queries fail when accessing properties of embedded components #15955

Closed

Description

@gsartori

where {} queries fail when accessing a property of an embedded component, even though the property is referenced using the expected dotted notation.

Hibernate throws the following exception:

org.hibernate.QueryException: Criteria objects cannot be created directly on components.
Create a criteria on owning entity and use a dotted property to access component property: extRef1

The query already uses a dotted property (extRef1.value), so it appears that GORM is translating the where {} closure into a Hibernate Criteria incorrectly.

The same happens with:

extRef1.provider == "SAP"

so the issue does not appear to be related to the =~ operator, but to accessing any property of an embedded component.

Expected behavior

The query should be translated into a predicate on the embedded property (e.g. extRef1.value) and execute successfully.

Actual Behaviour

Hibernate throws:

org.hibernate.QueryException: Criteria objects cannot be created directly on components.
Create a criteria on owning entity and use a dotted property to access component property: extRef1

NOTE: Removing the extRef1.value predicate makes the query execute correctly.

Steps To Reproduce

Domain model

class WorkItem extends SystemManaged {
    String description
}

Classes in /main/src

abstract class SystemManaged implements GormEntity {
    ExternalRef extRef1

    static embedded = ['extRef1']
}

class ExternalRef {
    String provider
    String value
}

Query

def query = WorkItem.where {}

String search = "ABC"

query = query.where {
    extRef1.value =~ "%${search}%"
}

Environment Information

Grails: 7.1.0

Example Application

No response

Version

7.1.0

Activity

  1. gsartori commented on Jul 10, 2026

    @gsartori
    ContributorAuthor

    The thread has reported my exact same experience:

    def q = A.where { prop3 == new B(prop4: 'bla') }
    def list = q.list()
    

    Embedded components are persisted inside the main domain class (owner) itself. It can be accessed directly using any dynamic finder as you do directly on a domain object.

    The above can also be represented in dynamic finders as:

    A.findAllByProp3(new B(prop4: 'bla'))
    

    In the reply below is what I need instead:

    [..] it parses it but I get zero results. Most probably because it's missing prop5 (which I don't know and can't filter on) [..]

  2. added this to the grails:8.0.0-M4 milestone on Jul 10, 2026
  3. jdaugherty commented on Jul 10, 2026

    @jdaugherty
    Contributor

    @gsartori I initially scheduled this for 8.x, we can backport it after review. #15962

  4. gsartori commented on Jul 11, 2026

    @gsartori
    ContributorAuthor

    From my side it would be fine to have it in Grails 8, thank you @jdaugherty

  5. added a commit that references this issue on Jul 19, 2026
    4ecf6d8
  6. added a commit that references this issue on Jul 30, 2026
    b0f3371
  7. added 3 commits that reference this issue on Aug 19, 2026
    72463be
    4ea0118
    413d19f
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

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions