You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
where {} queries fail when accessing properties of embedded components #15955
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
}
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) [..]
Activity
gsartori commentedon Jul 10, 2026
See also: https://stackoverflow.com/questions/18235180/gorm-where-query-on-an-embedded-object
gsartori commentedon Jul 10, 2026
The thread has reported my exact same experience:
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:
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) [..]
jdaugherty commentedon Jul 10, 2026
https://github.com/apache/grails-core/tree/fix/where-queries-embedded will fix this.
jdaugherty commentedon Jul 10, 2026
@gsartori I initially scheduled this for 8.x, we can backport it after review. #15962
gsartori commentedon Jul 11, 2026
From my side it would be fine to have it in Grails 8, thank you @jdaugherty
fix(grails-data-neo4j): implement embedded-component support and fix …
fix(grails-data-neo4j): implement embedded-component support and fix …
fix(grails-data-neo4j): implement embedded-component support and fix …
fix(grails-data-neo4j): implement embedded-component support and fix …
Neo4j GormRegistry migration (consolidated: replaces #15816, #15951, #…