From 494aa400e20d5b61d82a70bd340419a5e2ff314a Mon Sep 17 00:00:00 2001 From: Equipe Mobile Mind Date: Thu, 13 Apr 2023 11:10:07 -0300 Subject: [PATCH] Fix class java.lang.Double cannot be cast to class java.lang.Long I got this error running the project in MongoDB 6. Apparently the db is returning a floating point for a 64-bit number. The solution is to convert the result to a Number and transform it into a long safely. --- .../mapping/mongo/engine/MongoCodecEntityPersister.groovy | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/grails-datastore-gorm-mongodb/src/main/groovy/org/grails/datastore/mapping/mongo/engine/MongoCodecEntityPersister.groovy b/grails-datastore-gorm-mongodb/src/main/groovy/org/grails/datastore/mapping/mongo/engine/MongoCodecEntityPersister.groovy index 7348a201..4ed758ad 100644 --- a/grails-datastore-gorm-mongodb/src/main/groovy/org/grails/datastore/mapping/mongo/engine/MongoCodecEntityPersister.groovy +++ b/grails-datastore-gorm-mongodb/src/main/groovy/org/grails/datastore/mapping/mongo/engine/MongoCodecEntityPersister.groovy @@ -393,7 +393,8 @@ class MongoCodecEntityPersister extends ThirdPartyCacheEntityPersister { Document result = dbCollection.findOneAndUpdate(new Document(MONGO_ID_FIELD, collectionName), new Document(INC_OPERATOR, new Document(NEXT_ID, 1L)), options) // result should never be null and we shouldn't come back with an error ,but you never know. We should just retry if this happens... if (result != null) { - return result.getLong(NEXT_ID) + final nextId = result.get(NEXT_ID, Number.class).longValue(); + return Long.valueOf(nextId); } else { attempts++ if (attempts > 3) {