Upgrading Grails MongoDB GORM broke projections on list properties

678 Views Asked by At

I am using Criteria with projections to get a list of tags on my Account domain. Like this:

def tags = Account.createCriteria().list { 
    projections { property("tags") } 
}

My Account domain:

class Account {
    static mapWith = "mongo"
    List<Tag> tags
    ...
    static embedded = ['tags']
}

BuildConfig.groovy

// using grails 2.3.8
plugins {
    runtime ":hibernate:3.6.10.17"
    compile ":mongodb:2.0.1"

This worked until I upgraded the MongoDB GORM plugin for grails from 2.0.1 to 3.0.1

    compile ":mongodb:3.0.1"

Now I see the following error...

The class [java.util.List] is not a known persistent type.
    at org.grails.datastore.mapping.core.AbstractSession.retrieveAll(AbstractSession.java:723)
    at org.grails.datastore.mapping.mongo.query.MongoQuery$AggregatedResultList.initializeFully(MongoQuery.java:1601)
    at org.grails.datastore.mapping.mongo.query.MongoQuery$AggregatedResultList.size(MongoQuery.java:1764)

Why did this work before but is failing now? I don't want to rewrite all my existing queries to use mongoDB's aggregation framework.

2

There are 2 best solutions below

0
On

You can avoid the conflict by removing hibernate from your plug-in manager

0
On

You can try the usual

grails clean
grails refresh-dependencies

Also check for a newer version of your plugin.

Another alternative is switch to this mongo plugin published a month ago, which is supposed to be compatible with GORM for Hibernate

'org.grails.plugins:mongodb:6.0.0.M2'