{"record":{"id":"52ef2c5e8d9584bc","repo":"greenrobot/greenDAO","slug":"protobuf-entities-do-not-support-realtions-curren","errorCode":null,"errorMessage":"Protobuf entities do not support realtions, currently","messagePattern":"Protobuf entities do not support realtions, currently","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"DaoGenerator/src/org/greenrobot/greendao/generator/Entity.java","lineNumber":207,"sourceCode":"        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).\n     */\n    public ToOne addToOne(Entity target, Property fkProperty) {\n        if (protobuf) {\n            throw new IllegalStateException(\"Protobuf entities do not support realtions, currently\");\n        }\n\n        Property[] fkProperties = {fkProperty};\n        ToOne toOne = new ToOne(schema, this, target, fkProperties, true);\n        toOneRelations.add(toOne);\n        return toOne;\n    }\n\n    /** Convenience for {@link #addToOne(Entity, Property)} with a subsequent call to {@link ToOne#setName(String)}. */\n    public ToOne addToOne(Entity target, Property fkProperty, String name) {\n        ToOne toOne = addToOne(target, fkProperty);\n        toOne.setName(name);\n        return toOne;\n    }\n\n    public ToOne addToOneWithoutProperty(String name, Entity target, String fkColumnName) {\n        return addToOneWithoutProperty(name, target, fkColumnName, false, false);\n    }","sourceCodeStart":189,"sourceCodeEnd":225,"githubUrl":"https://github.com/greenrobot/greenDAO/blob/0bbb338e17c4cf28aba5aae62d42f73f50186157/DaoGenerator/src/org/greenrobot/greendao/generator/Entity.java#L189-L225","documentation":"Entity.addToOne rejects to-one relations on protobuf-mapped entities, throwing IllegalStateException with the (typo'd) message \"Protobuf entities do not support realtions, currently\". Protobuf code generation supports only field mapping, not greenDAO relation objects.","triggerScenarios":"Calling entity.addToOne(target, fkProperty) (or helpers toOne(), createRelation(), createTreeEntity()) on an entity in a protobuf-enabled schema.","commonSituations":"Reusing an existing relational schema definition after adding schema.enableProtobuf(); copy-pasting entity setup code between protobuf and non-protobuf schemas; using sample code like createTreeEntity with protobuf enabled.","solutions":["Remove the addToOne call or use a plain foreign-key property instead.","Remove schema.enableProtobuf() if relations are required.","Define protobuf entities with only scalar properties and store relation keys manually.","Keep two schema instances: protobuf-only for export, relational for DAO generation."],"exampleFix":"// before\nschema.enableProtobuf();\norder.addToOne(customer, customerId); // throws\n// after\norder.addLongProperty(\"customerId\");\n// (or remove enableProtobuf() to keep addToOne)","handlingStrategy":"validation","validationCode":"if (schema.isProtobuf()) {\n    throw new IllegalArgumentException(\"addToOne not allowed on protobuf entity \" + entity.getClassName());\n}","typeGuard":null,"tryCatchPattern":"try {\n    entity.addToOne(target, fkProperty);\n} catch (IllegalStateException e) {\n    if (e.getMessage().contains(\"Protobuf entities\")) {\n        entity.addLongProperty(\"targetId\"); // plain property fallback\n        return;\n    }\n    throw e;\n}","preventionTips":["Never copy relation-building code into protobuf-enabled schemas","Grep for addToOne/addToMany after enabling protobuf mode","Keep relational and protobuf schemas as separate Schema instances","Model protobuf relations as scalar FK fields only"],"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"}