{"record":{"id":"316a402475432592","repo":"greenrobot/greenDAO","slug":"duplicate-property-ordinals","errorCode":null,"errorMessage":"Duplicate property ordinals","messagePattern":"Duplicate property ordinals","errorType":"exception","errorClass":"DaoException","httpStatus":null,"severity":"critical","filePath":"DaoCore/src/main/java/org/greenrobot/greendao/internal/DaoConfig.java","lineNumber":118,"sourceCode":"        Class<?> propertiesClass = Class.forName(daoClass.getName() + \"$Properties\");\n        Field[] fields = propertiesClass.getDeclaredFields();\n\n        ArrayList<Property> propertyList = new ArrayList<Property>();\n        final int modifierMask = Modifier.STATIC | Modifier.PUBLIC;\n        for (Field field : fields) {\n            // There might be other fields introduced by some tools, just ignore them (see issue #28)\n            if ((field.getModifiers() & modifierMask) == modifierMask) {\n                Object fieldValue = field.get(null);\n                if (fieldValue instanceof Property) {\n                    propertyList.add((Property) fieldValue);\n                }\n            }\n        }\n\n        Property[] properties = new Property[propertyList.size()];\n        for (Property property : propertyList) {\n            if (properties[property.ordinal] != null) {\n                throw new DaoException(\"Duplicate property ordinals\");\n            }\n            properties[property.ordinal] = property;\n        }\n        return properties;\n    }\n\n    /** Does not copy identity scope. */\n    public DaoConfig(DaoConfig source) {\n        db = source.db;\n        tablename = source.tablename;\n        properties = source.properties;\n        allColumns = source.allColumns;\n        pkColumns = source.pkColumns;\n        nonPkColumns = source.nonPkColumns;\n        pkProperty = source.pkProperty;\n        statements = source.statements;\n        keyIsNumeric = source.keyIsNumeric;\n    }","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/greenrobot/greenDAO/blob/0bbb338e17c4cf28aba5aae62d42f73f50186157/DaoCore/src/main/java/org/greenrobot/greendao/internal/DaoConfig.java#L100-L136","documentation":"During DAO configuration, greenDAO collects entity properties from generated classes into a list and places each into an array indexed by its `ordinal`. If two Property instances share the same ordinal value, the slot would be overwritten, so a DaoException is thrown. Ordinals must be unique because they map to bind-parameter positions in generated SQL.","triggerScenarios":"A generated entity class (or custom static Property fields) declares two properties with the same ordinal value, typically due to hand-edited generated code, stale generated files after schema edits, or duplicate column definitions.","commonSituations":"Running an outdated code generator after adding columns; manually editing *Dao.java files; copy-pasting Property constants between entities without changing ordinals; partial/corrupt build artifacts from annotation processing.","solutions":["Run the greenDAO generator (DaoGenerator) to regenerate all entity and Dao classes from your schema definition","Clean and rebuild the project so stale generated classes are replaced","Inspect the entity class for two static Property fields with the same ordinal value and correct the schema so each column gets a unique ordinal","Ensure no manually added Property constants duplicate generated ones"],"exampleFix":"// before (in entity class)\npublic static final Property Name = new Property(0, String.class, \"name\", false, \"NAME\");\npublic static final Property Age = new Property(0, Long.class, \"age\", false, \"AGE\");\n// after\npublic static final Property Name = new Property(0, String.class, \"name\", false, \"NAME\");\npublic static final Property Age = new Property(1, Long.class, \"age\", false, \"AGE\");","handlingStrategy":"validation","validationCode":"long distinctOrdinals = allProperties.stream().mapToInt(p -> p.ordinal).distinct().count();\nif (distinctOrdinals != allProperties.size()) throw new IllegalStateException(\"Duplicate Property ordinals in entity\");","typeGuard":null,"tryCatchPattern":"try {\n    dao = new MyDao(db, config);\n} catch (DaoException e) {\n    if (e.getMessage().contains(\"Duplicate property ordinals\")) {\n        // regenerate entity/Dao classes before app start\n    }\n}","preventionTips":["Never hand-edit generated *Dao.java or entity Property constants","Always regenerate via DaoGenerator after schema changes","Add a unit test asserting unique ordinals per entity","Clean builds when generated code seems out of sync"],"tags":["greendao","orm","code-generation","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"}