Skip to content

[3.1.4 + Hibernate4] DetachedCriteria returning list of domains used as subquery causes invalid SQL with empty SELECT clause to be generated #14648

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
droggo opened this issue Mar 29, 2016 · 1 comment

Comments

@droggo
Copy link
Contributor

droggo commented Mar 29, 2016

Having domains:

class Parent {
    String name
    static hasMany = [children: Child]
}
class Child {
    String name
    Related related
    static belongsTo = [parent: Parent]
}

User could execute following query with detached criteria as subquery:

DetachedCriteria subquery = new DetachedCriteria(Child).build {
    isNotNull 'name'
}
Parent.createCriteria().list {
    inList 'children', subquery
} 

But this will cause Syntax error in SQL statement error with .. (SELECT FROM CHILD .. as cause of the error. SELECT is empty. Workaround is to use projection in detached criteria, for example

projections {
    groupProperty 'id'
}

Example project is here: https://github.com/droggo/GrailsSubqueries
Integration Spec to demo this problem: https://github.com/droggo/GrailsSubqueries/blob/master/src/integration-test/groovy/error/DetachedCriteriaDomainSubqueryIntegrationSpec.groovy

@jameskleeh
Copy link
Contributor

Was pretty sure this was the same issue as #9931 but the test case is a little different so I'm not sure

@jdaugherty jdaugherty transferred this issue from apache/grails-data-mapping Apr 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants