JetBrains Mongo Error – Spring – Failed to instantiate

10 viewsjetbrains idekotlinmongodbspring
0

I’m getting this erratic error in that MongoDB cannot instantiate a simple data class.

Failed to instantiate com.example.timesheetapi.entities.project.ProjectEntity using constructor fun <init>(org.bson.types.ObjectId?, kotlin.String, kotlin.String, kotlin.String, com.example.timesheetapi.entities.project.ProjectIndustryInformationEntity): com.example.timesheetapi.entities.project.ProjectEntity with arguments 65f8491015def041ff8f527f,UNITED_KINGDOM_PROJECT,Adventures,UNITED_KINGDOM,ProjectIndustryInformationEntity(sicCode=SIC_522, sicDescription=work activities)",

When I re-build the entity file it sometimes work. But I end up usually having to go to mongodb, deleting the entity from the collection and creating a new one.

  @Document(collection = "projects")
    @TypeAlias("PROJECT")
    internal sealed class ProjectEntity(
        @Id
        var _id: ObjectId?,                                                     // Primary key field
        var _class: String,
        var name: String,
        var country: String,
        var industryInformation: ProjectIndustryInformationEntity = ProjectIndustryInformationEntity(),
    ) : BaseEntity


    @Document(collection = "projects")
    @TypeAlias("UNITED_KINGDOM_PROJECT")
    internal class UnitedKingdomSubclassEntity(
        _id: ObjectId?,                                                         // Primary key field
        _class: String,
        name: String,
        country: String,
        industryInformation: ProjectIndustryInformationEntity = ProjectIndustryInformationEntity(),
        var engagementDetails: ProjectEngagementDetailsEntity = ProjectEngagementDetailsEntity()
) : ProjectEntity(_id, _class, name, country, industryInformation)

It’s as though most times it is not recognising the subclass (from the field UNITED_KINGDOM_PROJECT), and sometimes (after rebooting, recompiling, and rebuilding) it is is…

Any ideas?