tircnf opened a new issue, #14425:
URL: https://github.com/apache/grails-core/issues/14425
### Task List
- [x] Steps to reproduce provided
- [NA] Stacktrace (if present) provided
- [x] Example that reproduces the problem uploaded to Github
- [x] Full description of the issue provided (see below)
### Steps to Reproduce
1. create a where query that joins in a related class:
2. Don't execute the where query.
```
@Entity
class Pet {
static hasMany = [nickNames: NickName]
String name
}
@Entity
class NickName {
static belongsTo = [pet: Pet]
String nickname
}
def query = Pet.where {
def tags = nickNames
tags.nickname == "Spot"
order("tags.nickname")
}
```
### Expected Behaviour
No sql statements should be executed.
### Actual Behaviour
A `count(*)` query is executed on the relationship table.
`select count(*) as y0_ from nick_name this_ limit ?`
### Environment Information
- **Operating System**: windows
- **GORM Version:** 7.0.8
- **Grails Version (if using Grails):** 4.0.10
- **JDK Version:** 8
### Example Application
https://github.com/tircnf/ExtraQuery
The only source code in the project is the following hibernateSpec which
requires that sql logging be enabled in logback.groovy.
```
logger 'org.hibernate.SQL', DEBUG
```
```
import grails.persistence.Entity
import grails.test.hibernate.HibernateSpec
import org.junit.Rule
import org.springframework.boot.test.rule.OutputCapture
class ExtraQuerySpec extends HibernateSpec {
@Rule
OutputCapture capture = new OutputCapture()
@Override
List<Class> getDomainClasses() {
return [Pet, NickName]
}
void testSetup() {
expect:
true
!capture.toString()
}
void testLogging() {
expect:
new Pet(name: "jerry").save(flush: true, failOnError: true)
capture.toString().contains("insert into pet")
}
void testCriteria() {
when: "I create a detachedCriteria"
Pet.where {
}
then: "no query is executed"
!capture.toString()
}
void "test and query join criteria."() {
when: "I create query with join and projection"
Pet.where {
def tags = nickNames
tags.nickname == "Spot"
order("tags.nickname")
}
then: "No query should have been executed, but count(*) from
nick_name runs."
!capture.toString()
}
}
@Entity
class Pet {
static hasMany = [nickNames: NickName]
String name
}
@Entity
class NickName {
static belongsTo = [pet: Pet]
String nickname
}
```
--
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]