{"record":{"id":"eab843a89a01bafe","repo":"greenrobot/greenDAO","slug":"protobuf-entities-do-not-support-relations-curren","errorCode":null,"errorMessage":"Protobuf entities do not support relations, currently","messagePattern":"Protobuf entities do not support relations, currently","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"DaoGenerator/src/org/greenrobot/greendao/generator/Entity.java","lineNumber":185,"sourceCode":"    public ToMany addToMany(Entity target, Property targetProperty, String name) {\n        ToMany toMany = addToMany(target, targetProperty);\n        toMany.setName(name);\n        return toMany;\n    }\n\n    /**\n     * Add a to-many relationship; the target entity is joined using the given target property (of the target entity)\n     * and given source property (of this entity).\n     */\n    public ToMany addToMany(Property sourceProperty, Entity target, Property targetProperty) {\n        Property[] sourceProperties = {sourceProperty};\n        Property[] targetProperties = {targetProperty};\n        return addToMany(sourceProperties, target, targetProperties);\n    }\n\n    public ToMany addToMany(Property[] sourceProperties, Entity target, Property[] targetProperties) {\n        if (protobuf) {\n            throw new IllegalStateException(\"Protobuf entities do not support relations, currently\");\n        }\n\n        ToMany toMany = new ToMany(schema, this, sourceProperties, target, targetProperties);\n        toManyRelations.add(toMany);\n        target.incomingToManyRelations.add(toMany);\n        return toMany;\n    }\n\n    public ToManyWithJoinEntity addToMany(Entity target, Entity joinEntity, Property id1, Property id2) {\n        ToManyWithJoinEntity toMany = new ToManyWithJoinEntity(schema, this, target, joinEntity, id1, id2);\n        toManyRelations.add(toMany);\n        target.incomingToManyRelations.add(toMany);\n        return toMany;\n    }\n\n    /**\n     * Adds a to-one relationship to the given target entity using the given given foreign key property (which belongs\n     * to this entity).","sourceCodeStart":167,"sourceCodeEnd":203,"githubUrl":"https://github.com/greenrobot/greenDAO/blob/0bbb338e17c4cf28aba5aae62d42f73f50186157/DaoGenerator/src/org/greenrobot/greendao/generator/Entity.java#L167-L203","documentation":"Entity.addToMany rejects relation definitions on protobuf-mapped entities. Protobuf entity generation only supports simple field mapping, not greenDAO relations (to-many), so an IllegalStateException is thrown at schema definition time.","triggerScenarios":"Calling entity.addToMany(...) (directly or via the addToMany(sourceProperty, target, targetProperty) overload) when the entity was created with schema.enableProtobuf() / new Entity(..., protobuf=true).","commonSituations":"Enabling protobuf mode on a schema that also defines relational models; migrating a classic greenDAO schema to protobuf without removing relation declarations.","solutions":["Remove the addToMany call for the protobuf entity.","Disable protobuf mode (don't call schema.enableProtobuf()) if you need relations.","Model the relation manually by adding plain foreign-key properties instead of relation objects.","Split the schema: keep relational entities in a non-protobuf schema."],"exampleFix":"// before\nschema.enableProtobuf();\nuser.addToMany(note, userId); // unsupported\n// after\nuser.addLongProperty(\"noteId\"); // plain property, no relation\n// (or drop enableProtobuf() to keep relations)","handlingStrategy":"validation","validationCode":"if (schema.isProtobuf()) {\n    throw new IllegalArgumentException(\"addToMany not allowed on protobuf entity \" + entity.getClassName());\n}","typeGuard":null,"tryCatchPattern":"try {\n    entity.addToMany(sourceProps, target, targetProps);\n} catch (IllegalStateException e) {\n    if (e.getMessage().contains(\"Protobuf entities\")) {\n        throw new IllegalStateException(\"Remove enableProtobuf() or model FKs as plain properties\", e);\n    }\n    throw e;\n}","preventionTips":["Decide protobuf vs relational mode before writing entity definitions","Keep protobuf schemas free of any addToOne/addToMany calls","Review schema code after toggling enableProtobuf()","Use plain FK properties when protobuf mode is required"],"tags":["greendao","code-generation","protobuf","unsupported"],"backgroundTag":"unsupported-operation","analyzedSha":"0bbb338e17c4cf28aba5aae62d42f73f50186157","analyzedAt":"2026-09-08T03:22:36.050Z","contentChangedAt":"2026-09-08T03:22:36.050Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}