scaiandre opened a new issue, #14370:
URL: https://github.com/apache/grails-core/issues/14370
### Steps to Reproduce
grails create-app brokenMixingOfHibernateCriterionWithFormCriteria
cd brokenMixingOfHibernateCriterionWithFormCriteria
./grailsw create-domain-class Author
./grailsw create-domain-class Book
```
class Book {
String bookName
Author author
static constraints = {
}
}
```
```
class Author {
String authorName
static constraints = {
}
}
```
Have this clause in logback.xml:
```
<logger name="org.hibernate.SQL" level="DEBUG"/>
```
Try to use the domain classes in a controller or service as follows:
Use createCriteria and add a org.hibernate.criterion.Restriction to the
query in a or-clause.
```
final authors = Author.createCriteria().listDistinct {
HibernateCriteriaBuilder hibernateCriteriaBuilder = delegate as
HibernateCriteriaBuilder
hibernateCriteriaBuilder.projections {
hibernateCriteriaBuilder.property "id"
}
or {
add Restrictions.eq("id", 1L)
eq "authorName", "author1"
}
}
```
Execute the code.
### Expected Behaviour
Expected generated sql (to be seen on console):
```
SELECT this_.id AS y0_
FROM author this_
WHERE this_.id = ?
OR ( this_.author_name = ? )
```
### Actual Behaviour
generated sql (to be seen on console):
```
SELECT this_.id AS y0_
FROM author this_
WHERE this_.id = ?
AND ( this_.author_name = ? )
```
Note, that there is an AND clause generated instead of an OR clause.
### Environment Information
- **Operating System**: Ubuntu 20.04 LTS
- **Grails Version (if using Grails):** Grails 5.1.2
- **JDK Version:** Java 11.0.13
### Demo
https://github.com/scaiandre/grails-gorm-issue-detachedCriteria
./gradlew bootRun
curl http://localhost:8080/brokenMixingOfHibernateCriterionWithFormCriteria/
--
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]