{"record":{"id":"7bd234d02c51735e","repo":"greenrobot/greenDAO","slug":"property-already-defined","errorCode":null,"errorMessage":"Property already defined: ","messagePattern":"Property already defined: ","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"DaoGenerator/src/org/greenrobot/greendao/generator/Entity.java","lineNumber":143,"sourceCode":"    public PropertyBuilder addDoubleProperty(String propertyName) {\n        return addProperty(PropertyType.Double, propertyName);\n    }\n\n    public PropertyBuilder addByteArrayProperty(String propertyName) {\n        return addProperty(PropertyType.ByteArray, propertyName);\n    }\n\n    public PropertyBuilder addStringProperty(String propertyName) {\n        return addProperty(PropertyType.String, propertyName);\n    }\n\n    public PropertyBuilder addDateProperty(String propertyName) {\n        return addProperty(PropertyType.Date, propertyName);\n    }\n\n    public PropertyBuilder addProperty(PropertyType propertyType, String propertyName) {\n        if (!propertyNames.add(propertyName)) {\n            throw new RuntimeException(\"Property already defined: \" + propertyName);\n        }\n        PropertyBuilder builder = new PropertyBuilder(schema, this, propertyType, propertyName);\n        properties.add(builder.getProperty());\n        return builder;\n    }\n\n    /** Adds a standard _id column required by standard Android classes, e.g. list adapters. */\n    public PropertyBuilder addIdProperty() {\n        PropertyBuilder builder = addLongProperty(\"id\");\n        builder.dbName(\"_id\").primaryKey();\n        return builder;\n    }\n\n    /** Adds a to-many relationship; the target entity is joined to the PK property of this entity (typically the ID). */\n    public ToMany addToMany(Entity target, Property targetProperty) {\n        Property[] targetProperties = {targetProperty};\n        return addToMany(null, target, targetProperties);\n    }","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/greenrobot/greenDAO/blob/0bbb338e17c4cf28aba5aae62d42f73f50186157/DaoGenerator/src/org/greenrobot/greendao/generator/Entity.java#L125-L161","documentation":"Entity.addProperty keeps a set of property names and throws if the name was already added. Duplicate property names would produce invalid generated Java/SQL, so the schema DSL rejects them at definition time. All addXxxProperty helpers (addBooleanProperty, addIntProperty, etc.) funnel through addProperty.","triggerScenarios":"Calling entity.addIntProperty(\"id\") twice, or combining addIdProperty() with an explicit addLongProperty(\"id\") / addProperty(PropertyType.Long, \"id\") on the same entity.","commonSituations":"Copy-pasting entity definitions; adding a custom property that collides with an implicit id property; merging schema code from branches where both defined the same column; refactoring where a base entity helper is invoked along with a manual duplicate.","solutions":["Remove or rename the duplicate addXxxProperty call so each property name is unique per entity.","If you intended a primary key, use addIdProperty() once instead of adding a separate \"id\" property.","Keep entity schema definitions in one place to avoid split definitions across files/branches.","Track property names in a constant list and generate the calls to guarantee uniqueness."],"exampleFix":"// before\nentity.addIdProperty();\nentity.addLongProperty(\"id\"); // duplicate\n// after\nentity.addIdProperty(); // single definition","handlingStrategy":"validation","validationCode":"Set<String> seen = new HashSet<>();\nfor (String name : propertyNames) {\n    if (!seen.add(name)) throw new IllegalArgumentException(\"Duplicate property: \" + name);\n}","typeGuard":null,"tryCatchPattern":"try {\n    entity.addIntProperty(\"id\");\n} catch (RuntimeException e) {\n    if (e.getMessage().startsWith(\"Property already defined\")) {\n        log.warn(\"Skipping duplicate property: \" + e.getMessage());\n        return;\n    }\n    throw e;\n}","preventionTips":["Define all properties of an entity in one code block","Never combine addIdProperty() with a manual \"id\" property","Search the schema file for the property name before adding","Centralize shared entity helpers so definitions can't be duplicated"],"tags":["greendao","code-generation","duplicate","schema"],"backgroundTag":"schema-validation-failed","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"}