Skip to content

Using size() for collection associations in where-queries or detached criteria leads to exception #14344

Closed

Description

@miq

We are using Grails 5.2.5 annd GORM 7.3.2 with Hibernate5.

We have a domain object with a collection/list of other domain object and would like to do something like:

    Container.where {
        parts.size() == 1
        parts{ id == 123 }
    }.deleteAll()

As per documentation (section 7.4.5) this is supported by both where-queries and detached criteria: http://gorm.grails.org/latest/hibernate/manual/index.html#whereQueries

Doing so leads to the exception:

Caused by: org.springframework.dao.InvalidDataAccessResourceUsageException: Queries of type SizeEquals are not supported by this implementation
at org.grails.datastore.mapping.query.jpa.JpaQueryBuilder.buildWhereClauseForCriterion(JpaQueryBuilder.java:906)
at org.grails.datastore.mapping.query.jpa.JpaQueryBuilder.buildWhereClause(JpaQueryBuilder.java:859)
at org.grails.datastore.mapping.query.jpa.JpaQueryBuilder.buildWhereClause(JpaQueryBuilder.java:847)
at org.grails.datastore.mapping.query.jpa.JpaQueryBuilder.buildDelete(JpaQueryBuilder.java:143)
at org.grails.orm.hibernate.HibernateSession.lambda$deleteAll$0(HibernateSession.java:96)
at org.grails.orm.hibernate.GrailsHibernateTemplate.doExecute(GrailsHibernateTemplate.java:297)
at org.grails.orm.hibernate.GrailsHibernateTemplate.execute(GrailsHibernateTemplate.java:241)
at org.grails.orm.hibernate.HibernateSession.deleteAll(HibernateSession.java:92)
at grails.gorm.DetachedCriteria$_deleteAll_closure6.doCall(DetachedCriteria.groovy:561)

Activity

  1. jamesfredley commented on Feb 26, 2026

    @jamesfredley
    Contributor

    Fix submitted in PR #15460 - registers SizeEquals, SizeNotEquals, SizeGreaterThan, SizeGreaterThanEquals, SizeLessThan, and SizeLessThanEquals handlers in JpaQueryBuilder, using the JPQL SIZE() function. This resolves the "not supported" error when using size() in where-queries with deleteAll()/updateAll().

  2. added a commit that references this issue on Feb 27, 2026
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