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
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:
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:
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:
NOTE: Removing the extRef1.value predicate makes the query execute correctly.
Steps To Reproduce
Domain model
Classes in
/main/srcQuery
Environment Information
Grails: 7.1.0
Example Application
No response
Version
7.1.0