{"record":{"id":"224585afe1101914","repo":"greenrobot/greenDAO","slug":"property-does-not-exist-in","errorCode":null,"errorMessage":"Property  does not exist in ","messagePattern":"Property  does not exist in ","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"DaoGenerator/src/org/greenrobot/greendao/generator/Entity.java","lineNumber":725,"sourceCode":"\n    private void checkAdditionalImportsEntityTargetEntity(Entity targetEntity) {\n        if (!targetEntity.getJavaPackage().equals(javaPackage)) {\n            additionalImportsEntity.add(targetEntity.getJavaPackage() + \".\" + targetEntity.getClassName());\n        }\n        if (!targetEntity.getJavaPackageDao().equals(javaPackage)) {\n            additionalImportsEntity.add(targetEntity.getJavaPackageDao() + \".\" + targetEntity.getClassNameDao());\n        }\n    }\n\n    private void checkAdditionalImportsDaoTargetEntity(Entity targetEntity) {\n        if (!targetEntity.getJavaPackage().equals(javaPackageDao)) {\n            additionalImportsDao.add(targetEntity.getJavaPackage() + \".\" + targetEntity.getClassName());\n        }\n    }\n\n    public void validatePropertyExists(Property property) {\n        if (!properties.contains(property)) {\n            throw new RuntimeException(\"Property \" + property + \" does not exist in \" + this);\n        }\n    }\n\n    public List<Index> getMultiIndexes() {\n        return multiIndexes;\n    }\n\n    public boolean isNonDefaultDbName() {\n        return nonDefaultDbName;\n    }\n\n    @Override\n    public String toString() {\n        return \"Entity \" + className + \" (package: \" + javaPackage + \")\";\n    }\n\n}\n","sourceCodeStart":707,"sourceCodeEnd":743,"githubUrl":"https://github.com/greenrobot/greenDAO/blob/0bbb338e17c4cf28aba5aae62d42f73f50186157/DaoGenerator/src/org/greenrobot/greendao/generator/Entity.java#L707-L743","documentation":"Entity.validatePropertyExists checks that a given Property instance actually belongs to the entity's properties list and throws if not. The generator calls this for foreign keys, index/unique properties, etc., because referencing a foreign Property instance would generate broken code. Note the message prints \"Property \" + property + \" does not exist in \" + entity.","triggerScenarios":"Passing a Property created on entity A to entity B's addToOne/addToMany/index calls, e.g. order.addToOne(customer, customer.id) instead of order's own fk property; or a Property from a different Schema instance.","commonSituations":"Copy-pasted schema code using the wrong entity's properties; refactoring that renamed/moved property statics; defining FK on the wrong entity (relations in greenDAO require the FK to live on the source entity for to-one).","solutions":["Pass a property defined on the same entity (create it with entity.addLongProperty(\"customerId\") and use that).","For to-one relations, declare the foreign-key property on the source entity, not the target.","Verify you're using Property instances from the same Schema object.","Fix stale imports/references after renaming property holder classes."],"exampleFix":"// before\norder.addToOne(customer, customer.id); // property belongs to customer\n// after\nProperty customerId = order.addLongProperty(\"customerId\").getProperty();\norder.addToOne(customer, customerId);","handlingStrategy":"validation","validationCode":"// verify the Property belongs to the entity before using it in relations\nif (!sourceEntity.getProperties().contains(fkProperty)) {\n    throw new IllegalArgumentException(\"FK property must be defined on \" + sourceEntity.getClassName());\n}","typeGuard":null,"tryCatchPattern":"try {\n    order.addToOne(customer, fk);\n} catch (RuntimeException e) {\n    if (e.getMessage().contains(\"does not exist in\")) {\n        throw new IllegalStateException(\"Wrong Property instance — define the FK on the source entity\", e);\n    }\n    throw e;\n}","preventionTips":["Create FK properties with entity.addXxxProperty(...) on the source entity itself","Never pass another entity's Property instances","Keep property references in local variables right after creation","Check imports/holders after refactoring schema code"],"tags":["greendao","code-generation","schema","foreign-key"],"backgroundTag":"entity-not-found","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"}