Skip to content

Error querying association with basic collection types #14610

Closed

Description

@ilmoralito

JdbcSQLException occurred when try to query an association defined with Basic Collection Types

Having Student domain class, with the following body

class Student {
String name
String email

static constraints = {
    name blank: false
    email blank: false, unique: true, email: true
}

static hasMany = [schools: String]

static mapping = {
    table 'students'
    schools joinTable: [column: 'school']
}

}

And from an StudentController action

def index() {
    List<String> emailList = Student.createCriteria().list {
        'in'('schools', ['School2'])

        projections {
            property 'email'
        }
    }

    render emailList
}

I am getting the following stacktrace

2017-06-21 16:22:23.146 ERROR --- [io-8080-exec-10] o.h.engine.jdbc.spi.SqlExceptionHelper : Parameter "#1" is not set; SQL statement:
select this_.email as y0_ from students this_ where this_.id in (?) [90012-194]
2017-06-21 16:22:23.188 ERROR --- [io-8080-exec-10] o.g.web.errors.GrailsExceptionResolver : JdbcSQLException occurred when processing request: [GET] /student/index
Parameter "#1" is not set; SQL statement:
select this_.email as y0_ from students this_ where this_.id in (?) [90012-194]. Stacktrace follows:

java.lang.reflect.InvocationTargetException: null
at org.grails.core.DefaultGrailsControllerClass$ReflectionInvoker.invoke(DefaultGrailsControllerClass.java:211)
at org.grails.core.DefaultGrailsControllerClass.invoke(DefaultGrailsControllerClass.java:188)
at org.grails.web.mapping.mvc.UrlMappingsInfoHandlerAdapter.handle(UrlMappingsInfoHandlerAdapter.groovy:90)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
at org.springframework.boot.web.filter.ApplicationContextHeaderFilter.doFilterInternal(ApplicationContextHeaderFilter.java:55)
at org.grails.web.servlet.mvc.GrailsWebRequestFilter.doFilterInternal(GrailsWebRequestFilter.java:77)
at org.grails.web.filters.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:67)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.hibernate.exception.GenericJDBCException: could not extract ResultSet
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:47)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:111)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:97)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:79)
at org.hibernate.loader.Loader.getResultSet(Loader.java:2122)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1905)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1881)
at org.hibernate.loader.Loader.doQuery(Loader.java:925)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:342)
at org.hibernate.loader.Loader.doList(Loader.java:2622)
at org.hibernate.loader.Loader.doList(Loader.java:2605)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2434)
at org.hibernate.loader.Loader.list(Loader.java:2429)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:109)
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1787)
at org.hibernate.internal.CriteriaImpl.list(CriteriaImpl.java:363)
at org.grails.orm.hibernate.query.AbstractHibernateCriteriaBuilder.invokeMethod(AbstractHibernateCriteriaBuilder.java:1687)
at org.grails.orm.hibernate.query.AbstractHibernateCriteriaBuilder.list(AbstractHibernateCriteriaBuilder.java:1558)
at demo.app.StudentController.index(StudentController.groovy:6)
... 14 common frames omitted
Caused by: org.h2.jdbc.JdbcSQLException: Parameter "#1" is not set; SQL statement:
select this_.email as y0_ from students this_ where this_.id in (?) [90012-194]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:345)
at org.h2.message.DbException.get(DbException.java:179)
at org.h2.message.DbException.get(DbException.java:155)
at org.h2.expression.Parameter.checkSet(Parameter.java:81)
at org.h2.command.Prepared.checkParameters(Prepared.java:164)
at org.h2.command.CommandContainer.query(CommandContainer.java:112)
at org.h2.command.Command.executeQuery(Command.java:201)
at org.h2.jdbc.JdbcPreparedStatement.executeQuery(JdbcPreparedStatement.java:110)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:70)
... 29 common frames omitted

Steps to Reproduce

  1. Clone this repo https://github.com/ilmoralito/Error-querying-basic-collection-types
  2. Run the repo
  3. Go to this location http://localhost:8080/student/index

Expected Behaviour

Should print a list of student emails

Actual Behaviour

Error 500: Internal Server Error

URI /student/index
Class org.h2.jdbc.JdbcSQLException
Message null
Caused by Parameter "#1" is not set; SQL statement: select this_.email as y0_ from students this_ where this_.id in (?) [90012-194]

Environment Information

  • Operating System: Ubuntu
  • Grails Version: Using grails version 3.2.9
  • JDK Version: Using java version 8u121

Example Application

Activity

  1. dularion commented on May 3, 2018

    @dularion

    We have got the same issue. A workaround is to use HQL, but we really prefer criterias / where-queries. Are there any updates on this?

  2. dularion commented on May 4, 2018

    @dularion

    I just found this old stackoverflow. Does something like this still work? https://stackoverflow.com/questions/8347726/how-to-make-a-query-with-usage-of-like-operator-over-a-string-collection-in-gorm?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa

    def criteria = User.createCriteria()
    def results = criteria.listDistinct () {
      and {
        user.values.each {  like('someField', '%'+it+'%') }
      }
    }
    

    although I would pose the questions: what is user in that query?

  3. dularion commented on May 4, 2018

    @dularion

    How would that look like exactly? I tried something like this:

    def results = Student.where {
      schools {
        elements == 'School2'
      }
    }
    

    but that doesnt work

  4. zyro23 commented on May 4, 2018

    @zyro23
    Contributor

    unfortunately, i think no luck with detached-criteria/where-queries.
    but criteria should work:

    Student.createCriteria().list {
    	createAlias "schools", "s"
    	eq "s.elements", "School2"
    }
  5. jamesfredley commented on Feb 26, 2026

    @jamesfredley
    Contributor

    We have verified that this issue still exists in Grails 7.x / GORM 8.x.

    A reproduction test reproduces the exact same Parameter "#1" is not set error when using criteria queries with 'in' operator on a basic collection type (hasMany with String).

    This will be addressed in an upcoming fix.

  6. added 2 commits that reference this issue on Feb 26, 2026
  7. added 2 commits that reference this issue on Feb 27, 2026
  8. added a commit that references this issue on Jul 19, 2026
    4ecf6d8
  9. added a commit that references this issue on Jul 30, 2026
    b0f3371
  10. added 3 commits that reference this issue on Aug 19, 2026
    72463be
    4ea0118
    413d19f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions