Skip to content

subqueries not supported for DetachedCriteria queries #59

@musketyr

Description

@musketyr

even it looks that detached criteria are supported by DetachedCriteria.inList(String,QueryableCriteria) method to perform subqueries they fails with

No converter found capable of converting from type org.hibernate.criterion.DetachedCriteria to type java.lang.Long. Stacktrace follows:
Message: No converter found capable of converting from type org.hibernate.criterion.DetachedCriteria to type java.lang.Long
    Line | Method
->>  440 | applyDetachedCriteria in org.grails.datastore.gorm.finders.DynamicFinder
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   1200 | doCall                in grails.gorm.DetachedCriteria$_withPopulatedQuery_closure10
|    700 | doCall . . . . . . .  in org.grails.datastore.gorm.GormStaticApi$_withDatastoreSession_closure23
|    302 | execute               in org.grails.datastore.mapping.core.DatastoreUtils
|     37 | execute . . . . . . . in org.grails.datastore.gorm.AbstractDatastoreApi
|    699 | withDatastoreSession  in org.grails.datastore.gorm.GormStaticApi
|   1184 | withPopulatedQuery .  in grails.gorm.DetachedCriteria
|    843 | list                  in     ''
|     50 | getItems . . . . . .  in org.modelcatalogue.core.util.DetachedListWithTotalAndType
|     19 | getItems              in org.modelcatalogue.core.util.ListWithTotalAndTypeWrapper
|     23 | prepareJsonMap . . .  in org.modelcatalogue.core.util.marshalling.ListWrapperMarshaller
|     26 | doCall                in org.modelcatalogue.core.util.marshalling.AbstractMarshallers$_register_closure1
|    202 | value . . . . . . . . in grails.converters.JSON
|    134 | render                in     ''
|    116 | renderJson . . . . .  in org.grails.plugins.web.rest.render.json.DefaultJsonRenderer
|    110 | renderJson            in     ''
|     91 | render . . . . . . .  in     ''
|    177 | respond               in org.grails.plugins.web.rest.api.ControllersRestApi
|     59 | global . . . . . . .  in org.modelcatalogue.core.ChangeController
|    198 | doFilter              in grails.plugin.cache.web.filter.PageFragmentCachingFilter
|     63 | doFilter . . . . . .  in grails.plugin.cache.web.filter.AbstractFilter
|    150 | invoke                in net.bull.javamelody.JspWrapper
|    285 | invoke . . . . . . .  in net.bull.javamelody.JdbcWrapper$DelegatingInvocationHandler
|    198 | doFilter              in net.bull.javamelody.MonitoringFilter
|    176 | doFilter . . . . . .  in     ''
|     53 | doFilter              in grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter
|     49 | doFilter . . . . . .  in grails.plugin.springsecurity.web.authentication.RequestHolderAuthenticationFilter
|     82 | doFilter              in grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter
|   1145 | runWorker . . . . . . in java.util.concurrent.ThreadPoolExecutor
|    615 | run                   in java.util.concurrent.ThreadPoolExecutor$Worker
^    744 | run . . . . . . . . . in java.lang.Thread

Here is the simplified query which fails

DetachedCriteria<CatalogueElement> criteria = new DetachedCriteria<CatalogueElement>(CatalogueElement)

criteria.projections {
    property 'id'
}

List<Change> changes = new DetachedCriteria<Change>(Change).build  {
    inList 'changedId', criteria
    ne 'system', Boolean.TRUE
}.list()

The whole point is that the implementation in JpaQueryBuilder just expects an collection to be passed in not a query.

This happens in 2.4.3 but after taking look to the current code it doesn't seem to be fixed in later versions.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions