greenrobot/greenDAO · error · IllegalStateException

Protobuf entities do not support realtions, currently

Error message

Protobuf entities do not support realtions, currently

What it means

Entity.addToOne rejects to-one relations on protobuf-mapped entities, throwing IllegalStateException with the (typo'd) message "Protobuf entities do not support realtions, currently". Protobuf code generation supports only field mapping, not greenDAO relation objects.

Solutions

  1. Remove the addToOne call or use a plain foreign-key property instead.
  2. Remove schema.enableProtobuf() if relations are required.
  3. Define protobuf entities with only scalar properties and store relation keys manually.
  4. Keep two schema instances: protobuf-only for export, relational for DAO generation.

Example fix

// before
schema.enableProtobuf();
order.addToOne(customer, customerId); // throws
// after
order.addLongProperty("customerId");
// (or remove enableProtobuf() to keep addToOne)
Defensive patterns

Strategy: validation

Validate before calling

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

Try / catch

try {
    entity.addToOne(target, fkProperty);
} catch (IllegalStateException e) {
    if (e.getMessage().contains("Protobuf entities")) {
        entity.addLongProperty("targetId"); // plain property fallback
        return;
    }
    throw e;
}

Prevention

When it happens

Trigger: Calling entity.addToOne(target, fkProperty) (or helpers toOne(), createRelation(), createTreeEntity()) on an entity in a protobuf-enabled schema.

Common situations: Reusing an existing relational schema definition after adding schema.enableProtobuf(); copy-pasting entity setup code between protobuf and non-protobuf schemas; using sample code like createTreeEntity with protobuf enabled.

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/52ef2c5e8d9584bc. Report an issue: GitHub.

Appendix: source

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

        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).
     */
    public ToOne addToOne(Entity target, Property fkProperty) {
        if (protobuf) {
            throw new IllegalStateException("Protobuf entities do not support realtions, currently");
        }

        Property[] fkProperties = {fkProperty};
        ToOne toOne = new ToOne(schema, this, target, fkProperties, true);
        toOneRelations.add(toOne);
        return toOne;
    }

    /** Convenience for {@link #addToOne(Entity, Property)} with a subsequent call to {@link ToOne#setName(String)}. */
    public ToOne addToOne(Entity target, Property fkProperty, String name) {
        ToOne toOne = addToOne(target, fkProperty);
        toOne.setName(name);
        return toOne;
    }

    public ToOne addToOneWithoutProperty(String name, Entity target, String fkColumnName) {
        return addToOneWithoutProperty(name, target, fkColumnName, false, false);
    }

View on GitHub (pinned to 0bbb338e17)