greenrobot/greenDAO · error · RuntimeException
Property does not exist in
Error message
Property does not exist in
What it means
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.
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.
Example fix
// before
order.addToOne(customer, customer.id); // property belongs to customer
// after
Property customerId = order.addLongProperty("customerId").getProperty();
order.addToOne(customer, customerId); Defensive patterns
Strategy: validation
Validate before calling
// verify the Property belongs to the entity before using it in relations
if (!sourceEntity.getProperties().contains(fkProperty)) {
throw new IllegalArgumentException("FK property must be defined on " + sourceEntity.getClassName());
} Try / catch
try {
order.addToOne(customer, fk);
} catch (RuntimeException e) {
if (e.getMessage().contains("does not exist in")) {
throw new IllegalStateException("Wrong Property instance — define the FK on the source entity", e);
}
throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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).
Understand the failure class
Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.
Related errors
- Duplicate property ordinals
- Property already defined:
- AUTOINCREMENT is only available to primary key properties…
- No DAO registered for
- Could not init DAOConfig
AI-assisted analysis of greenrobot/greenDAO@0bbb338e17 (2026-09-08).
Data as JSON: /api/errors/224585afe1101914.
Report an issue: GitHub.
Appendix: source
Thrown at DaoGenerator/src/org/greenrobot/greendao/generator/Entity.java:725
private void checkAdditionalImportsEntityTargetEntity(Entity targetEntity) {
if (!targetEntity.getJavaPackage().equals(javaPackage)) {
additionalImportsEntity.add(targetEntity.getJavaPackage() + "." + targetEntity.getClassName());
}
if (!targetEntity.getJavaPackageDao().equals(javaPackage)) {
additionalImportsEntity.add(targetEntity.getJavaPackageDao() + "." + targetEntity.getClassNameDao());
}
}
private void checkAdditionalImportsDaoTargetEntity(Entity targetEntity) {
if (!targetEntity.getJavaPackage().equals(javaPackageDao)) {
additionalImportsDao.add(targetEntity.getJavaPackage() + "." + targetEntity.getClassName());
}
}
public void validatePropertyExists(Property property) {
if (!properties.contains(property)) {
throw new RuntimeException("Property " + property + " does not exist in " + this);
}
}
public List<Index> getMultiIndexes() {
return multiIndexes;
}
public boolean isNonDefaultDbName() {
return nonDefaultDbName;
}
@Override
public String toString() {
return "Entity " + className + " (package: " + javaPackage + ")";
}
}
View on GitHub (pinned to 0bbb338e17)