greenrobot/greenDAO · error · IllegalArgumentException
Unsupported type
Error message
Unsupported type: ${type} What it means
initIdentityScope chooses an identity-scope implementation based on the primary key type: numeric keys use IdentityScopeLong, everything else IdentityScopeObject. If the key property type is neither numeric nor String/byte-array eligible, the configuration is unsupported and IllegalArgumentException is thrown.
Solutions
- Change the entity primary key to a supported type (Long/long is recommended) and regenerate the DAO classes
- If a non-Long key is required, ensure the key property type is String or byte[] so IdentityScopeObject is selected
- Check the generated DaoConfig constructor to confirm the PK type matches the schema
Example fix
// before (schema/entity)
@Entity
public class User {
@Id
private Date createdAt;
}
// after
@Entity
public class User {
@Id(autoincrement = true)
private Long id;
@Unique
private Date createdAt;
} Defensive patterns
Strategy: validation
Validate before calling
Class<?> pkType = keyProperty.type;
boolean ok = pkType == Long.class || pkType == long.class || pkType == Integer.class || pkType == int.class
|| pkType == Short.class || pkType == short.class || pkType == Byte.class || pkType == byte.class
|| pkType == String.class || pkType == byte[].class;
if (!ok) throw new IllegalArgumentException("Unsupported PK type: " + pkType); Try / catch
try {
config.initIdentityScope();
} catch (IllegalArgumentException e) {
// fall back: disable identity scope or fix PK type
config.initIdentityScope(null);
} Prevention
- Use Long autoincrement primary keys for entities
- Avoid Date/Boolean/custom object primary keys
- Regenerate DAOs after changing PK types
When it happens
Trigger: Configuring a DAO whose primary key property `type` is not a supported key type (e.g. a non-numeric, non-String PK such as Date, Boolean, or a custom object) — passed via `initIdentityScope()` in DaoConfig.
Common situations: Declaring an entity with a primary key of an unusual Java type; changing a PK type in the schema without regenerating; custom DaoConfig construction in tests or non-standard setups.
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
Related errors
- ( ) does not have a single-column primary key
- Duplicate property ordinals
- Table alias required
- Method may be called only in owner thread, use…
- Illegal parameter index:
AI-assisted analysis of greenrobot/greenDAO@0bbb338e17 (2026-09-08).
Data as JSON: /api/errors/b6391e8a28ee1f71.
Report an issue: GitHub.
Appendix: source
Thrown at DaoCore/src/main/java/org/greenrobot/greendao/internal/DaoConfig.java:173
}
}
public void setIdentityScope(IdentityScope<?, ?> identityScope) {
this.identityScope = identityScope;
}
@SuppressWarnings("rawtypes")
public void initIdentityScope(IdentityScopeType type) {
if (type == IdentityScopeType.None) {
identityScope = null;
} else if (type == IdentityScopeType.Session) {
if (keyIsNumeric) {
identityScope = new IdentityScopeLong();
} else {
identityScope = new IdentityScopeObject();
}
} else {
throw new IllegalArgumentException("Unsupported type: " + type);
}
}
}
View on GitHub (pinned to 0bbb338e17)