greenrobot/greenDAO · error · RuntimeException
Property already defined:
Error message
Property already defined:
What it means
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.
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.
Example fix
// before
entity.addIdProperty();
entity.addLongProperty("id"); // duplicate
// after
entity.addIdProperty(); // single definition Defensive patterns
Strategy: validation
Validate before calling
Set<String> seen = new HashSet<>();
for (String name : propertyNames) {
if (!seen.add(name)) throw new IllegalArgumentException("Duplicate property: " + name);
} Try / catch
try {
entity.addIntProperty("id");
} catch (RuntimeException e) {
if (e.getMessage().startsWith("Property already defined")) {
log.warn("Skipping duplicate property: " + e.getMessage());
return;
}
throw e;
} Prevention
- 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
When it happens
Trigger: Calling entity.addIntProperty("id") twice, or combining addIdProperty() with an explicit addLongProperty("id") / addProperty(PropertyType.Long, "id") on the same entity.
Common situations: 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.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- Duplicate property ordinals
- Interface defined more than once:
- Duplicate name for
- Property does not exist in
- AUTOINCREMENT is only available to primary key properties…
AI-assisted analysis of greenrobot/greenDAO@0bbb338e17 (2026-09-08).
Data as JSON: /api/errors/7bd234d02c51735e.
Report an issue: GitHub.
Appendix: source
Thrown at DaoGenerator/src/org/greenrobot/greendao/generator/Entity.java:143
public PropertyBuilder addDoubleProperty(String propertyName) {
return addProperty(PropertyType.Double, propertyName);
}
public PropertyBuilder addByteArrayProperty(String propertyName) {
return addProperty(PropertyType.ByteArray, propertyName);
}
public PropertyBuilder addStringProperty(String propertyName) {
return addProperty(PropertyType.String, propertyName);
}
public PropertyBuilder addDateProperty(String propertyName) {
return addProperty(PropertyType.Date, propertyName);
}
public PropertyBuilder addProperty(PropertyType propertyType, String propertyName) {
if (!propertyNames.add(propertyName)) {
throw new RuntimeException("Property already defined: " + propertyName);
}
PropertyBuilder builder = new PropertyBuilder(schema, this, propertyType, propertyName);
properties.add(builder.getProperty());
return builder;
}
/** Adds a standard _id column required by standard Android classes, e.g. list adapters. */
public PropertyBuilder addIdProperty() {
PropertyBuilder builder = addLongProperty("id");
builder.dbName("_id").primaryKey();
return builder;
}
/** Adds a to-many relationship; the target entity is joined to the PK property of this entity (typically the ID). */
public ToMany addToMany(Entity target, Property targetProperty) {
Property[] targetProperties = {targetProperty};
return addToMany(null, target, targetProperties);
}View on GitHub (pinned to 0bbb338e17)