MongoDB Java Inserting Throws org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class io.github.ilkgunel.mongodb.Pojo

前端 未结 8 789
渐次进展
渐次进展 2020-12-11 00:25

I\'m learning MongoDB with Java. I\'m trying to insert data to MongoDB with Java driver. I\'m doing inserting like in MongoDB tutorial and every thing is okey. But if I want

8条回答
  •  抹茶落季
    2020-12-11 01:09

    I'm using MongoDB POJO support. In my case, I had this "clue" WARNing before the exception:

     org.bson.codecs.pojo                     : Cannot use 'UserBeta' with the PojoCodec.
    
    org.bson.codecs.configuration.CodecConfigurationException: Property 'premium' in UserBeta, has differing data types: TypeData{type=PremiumStatus} and TypeData{type=Boolean}.
    

    My class UserBeta had getPremium(), setPremium(), and isPremium(). I already @BsonIgnore-d the isPremium() but for some reason it's still detected and causing conflict.

    My workaround is to rename isPremium() to isAnyPremium().

提交回复
热议问题