greenrobot/greenDAO · error · IllegalStateException

Protobuf entities do not support relations, currently

Error message

Protobuf entities do not support relations, currently

What it means

Entity.addToMany rejects relation definitions on protobuf-mapped entities. Protobuf entity generation only supports simple field mapping, not greenDAO relations (to-many), so an IllegalStateException is thrown at schema definition time.

Solutions

  1. Remove the addToMany call for the protobuf entity.
  2. Disable protobuf mode (don't call schema.enableProtobuf()) if you need relations.
  3. Model the relation manually by adding plain foreign-key properties instead of relation objects.
  4. Split the schema: keep relational entities in a non-protobuf schema.

Example fix

// before
schema.enableProtobuf();
user.addToMany(note, userId); // unsupported
// after
user.addLongProperty("noteId"); // plain property, no relation
// (or drop enableProtobuf() to keep relations)
Defensive patterns

Strategy: validation

Validate before calling

if (schema.isProtobuf()) {
    throw new IllegalArgumentException("addToMany not allowed on protobuf entity " + entity.getClassName());
}

Try / catch

try {
    entity.addToMany(sourceProps, target, targetProps);
} catch (IllegalStateException e) {
    if (e.getMessage().contains("Protobuf entities")) {
        throw new IllegalStateException("Remove enableProtobuf() or model FKs as plain properties", e);
    }
    throw e;
}

Prevention

When it happens

Trigger: Calling entity.addToMany(...) (directly or via the addToMany(sourceProperty, target, targetProperty) overload) when the entity was created with schema.enableProtobuf() / new Entity(..., protobuf=true).

Common situations: Enabling protobuf mode on a schema that also defines relational models; migrating a classic greenDAO schema to protobuf without removing relation declarations.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of greenrobot/greenDAO@0bbb338e17 (2026-09-08). Data as JSON: /api/errors/eab843a89a01bafe. Report an issue: GitHub.

Appendix: source

Thrown at DaoGenerator/src/org/greenrobot/greendao/generator/Entity.java:185

    public ToMany addToMany(Entity target, Property targetProperty, String name) {
        ToMany toMany = addToMany(target, targetProperty);
        toMany.setName(name);
        return toMany;
    }

    /**
     * Add a to-many relationship; the target entity is joined using the given target property (of the target entity)
     * and given source property (of this entity).
     */
    public ToMany addToMany(Property sourceProperty, Entity target, Property targetProperty) {
        Property[] sourceProperties = {sourceProperty};
        Property[] targetProperties = {targetProperty};
        return addToMany(sourceProperties, target, targetProperties);
    }

    public ToMany addToMany(Property[] sourceProperties, Entity target, Property[] targetProperties) {
        if (protobuf) {
            throw new IllegalStateException("Protobuf entities do not support relations, currently");
        }

        ToMany toMany = new ToMany(schema, this, sourceProperties, target, targetProperties);
        toManyRelations.add(toMany);
        target.incomingToManyRelations.add(toMany);
        return toMany;
    }

    public ToManyWithJoinEntity addToMany(Entity target, Entity joinEntity, Property id1, Property id2) {
        ToManyWithJoinEntity toMany = new ToManyWithJoinEntity(schema, this, target, joinEntity, id1, id2);
        toManyRelations.add(toMany);
        target.incomingToManyRelations.add(toMany);
        return toMany;
    }

    /**
     * Adds a to-one relationship to the given target entity using the given given foreign key property (which belongs
     * to this entity).

View on GitHub (pinned to 0bbb338e17)