greenrobot/greenDAO · error · RuntimeException
Duplicate name for
Error message
Duplicate name for
What it means
During the generator's third init pass, init3rdPassRelations collects lowercased to-one relation names in a set and throws a RuntimeException if a name was already seen. Duplicate to-one names would generate clashing getter methods, so the generator fails early with the offending ToOne object in the message.
Solutions
- Give each to-one relation a unique name where supported, or ensure target entities differ so derived names differ.
- Remove one of the duplicate addToOne calls; if two FKs to the same entity are needed, rename the FK properties or use ToMany/projection instead.
- Check toOneRelations count per entity during schema setup and assert uniqueness yourself.
- Use distinct wrapper entities or manually modeled FK properties for multiple references to the same target type.
Example fix
// before
order.addToOne(address, billingAddressId); // name "address"
order.addToOne(address, shippingAddressId); // duplicate derived name
// after
order.addLongProperty("billingAddressId");
order.addLongProperty("shippingAddressId");
// and keep a single addToOne, or model both FKs as plain properties Defensive patterns
Strategy: validation
Validate before calling
Set<String> names = new HashSet<>();
// before generating: assert each entity's to-one targets are distinct
for (ToOne t : entity.getToOneRelations()) {
if (!names.add(t.getTargetEntity().getClassName().toLowerCase())) {
throw new IllegalStateException("Duplicate to-one to " + t.getTargetEntity().getClassName());
}
} Try / catch
try {
generateAll(schema);
} catch (RuntimeException e) {
if (e.getMessage().startsWith("Duplicate name for")) {
throw new IllegalStateException("Two to-one relations resolve to the same name — rename targets or model FKs manually", e);
}
throw e;
} Prevention
- Avoid two addToOne calls to the same target entity on one entity
- Give relations distinct target entities or use plain FK properties
- Count toOneRelations per entity in schema tests
- Document multiple-reference cases (billing/shipping) as plain properties
When it happens
Trigger: Calling entity.addToOne(target, fk) twice on the same entity where both ToOne relations resolve to the same generated name (often because the relation name derives from the target entity name, e.g. two to-one relations to the same target entity).
Common situations: Two foreign keys pointing to the same target entity (e.g. order.billToAddress and order.shipToAddress both via addToOne(address, ...)) without custom names; copy-pasted relation declarations; loop/tree entities where parent/child both target the same class without naming overrides.
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
- Property already defined:
- Interface defined more than once:
- No DAO registered for
- Could not init DAOConfig
- Duplicate property ordinals
AI-assisted analysis of greenrobot/greenDAO@0bbb338e17 (2026-09-08).
Data as JSON: /api/errors/b14f5d749b85f265.
Report an issue: GitHub.
Appendix: source
Thrown at DaoGenerator/src/org/greenrobot/greendao/generator/Entity.java:639
}
}
}
void init3rdPass() {
for (Property property : properties) {
property.init3ndPass();
}
init3rdPassRelations();
init3rdPassAdditionalImports();
}
private void init3rdPassRelations() {
Set<String> toOneNames = new HashSet<>();
for (ToOne toOne : toOneRelations) {
toOne.init3ndPass();
if (!toOneNames.add(toOne.getName().toLowerCase())) {
throw new RuntimeException("Duplicate name for " + toOne);
}
}
Set<String> toManyNames = new HashSet<>();
for (ToManyBase toMany : toManyRelations) {
toMany.init3rdPass();
if (toMany instanceof ToMany) {
Entity targetEntity = toMany.getTargetEntity();
for (Property targetProperty : ((ToMany) toMany).getTargetProperties()) {
if (!targetEntity.propertiesColumns.contains(targetProperty)) {
targetEntity.propertiesColumns.add(targetProperty);
}
}
}
if (!toManyNames.add(toMany.getName().toLowerCase())) {
throw new RuntimeException("Duplicate name for " + toMany);
}
}View on GitHub (pinned to 0bbb338e17)