gustavoharff opened a new issue, #16633:
URL: https://github.com/apache/grails-core/issues/16633
### Expected Behavior
A collection criterion such as `isNotEmpty('pets')` restricts the collection
whether it comes before or after a `pets { ... }` block in the same criteria,
at the top level or inside another association block.
### Actual Behaviour
On Hibernate 7, unless the criterion comes before the block inside another
association block, the query fails with:
```
java.lang.ClassCastException: class
org.hibernate.query.sqm.tree.domain.SqmSetJoin cannot be cast to class
org.hibernate.query.sqm.tree.domain.SqmPluralValuedSimplePath
```
The path `pets` resolves to the join the block made for the association
instead of to the collection-valued path that `isNotEmpty` expects. At the top
level this happens in either order, because the join type a block of the
queried class records becomes an alias definition of the query.
### Steps To Reproduce
With the TCK `Person` (`hasMany = [pets: Pet]`) and `Pet` (`owner`) domains
on Hibernate 7:
```groovy
// top level, block first: ClassCastException
Person.createCriteria().list {
pets { eq('name', 'Rex') }
isNotEmpty('pets')
}
// top level, criterion first: ClassCastException
Person.createCriteria().list {
isNotEmpty('pets')
pets { eq('name', 'Rex') }
}
// inside another block, block first: ClassCastException
Pet.createCriteria().list {
owner {
pets { eq('name', 'Rex') }
isNotEmpty('pets')
}
}
// inside another block, criterion first: works
Pet.createCriteria().list {
owner {
isNotEmpty('pets')
pets { eq('name', 'Rex') }
}
}
```
Found while reviewing
https://github.com/apache/grails-core/pull/16559#discussion_r4256550230; the
behaviour is the same with and without that PR.
### Environment Information
- Hibernate 7 (`grails-data-hibernate7`), Hibernate ORM 7.4.10
- JDK 21
### Example Application
_No response_
### Version
8.0.x
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]