greenrobot/greenDAO · error · DaoException

No DAO registered for

Error message

No DAO registered for ${entityClass}

What it means

AbstractDaoSession keeps a registry (entityToDao) of entity classes to DAO instances. getDao(entityClass) throws DaoException when the class is not registered — i.e., the session was not built with a DAO for that entity, or a different Class object/subtype was passed.

Solutions

  1. Regenerate DaoSession/DaoMaster (greenDAO Gradle plugin/generator) so the new entity's DAO is registered in the constructor's dao registration list.
  2. Use the exact registered entity class (not a subclass) in getDao().
  3. Ensure the app uses the generated DaoSession (new DaoMaster(db).newSession()) rather than a hand-built one.
  4. Verify there is only one schema definition/generation output on the classpath (no stale generated files).

Example fix

// before (subclass)
Dao dao = session.getDao(AdminUser.class); // AdminUser extends User -> not registered
// after
Dao dao = session.getDao(User.class); // exact registered entity class
Defensive patterns

Strategy: validation

Validate before calling

if (!session.getRegisteredDaos().containsKey(entityClass)) {
    throw new IllegalStateException("Entity not in schema: " + entityClass);
}

Type guard

boolean isRegistered(AbstractDaoSession s, Class<?> c) { return s.getDao(c) != null; }
// or wrap: try { s.getDao(c); return true; } catch (DaoException e) { return false; }

Try / catch

try {
    AbstractDao<?, ?> dao = session.getDao(EntityClass.class);
} catch (DaoException e) {
    if (e.getMessage().startsWith("No DAO registered for")) {
        // regenerate DaoSession or pass the correct entity class
    } else throw e;
}

Prevention

When it happens

Trigger: Calling session.getDao(SomeEntity.class) for an entity not added to the schema/master generating the session; passing a subclass of a registered entity class; calling queryBuilder()/dao conveniences via a session lacking the DAO registration.

Common situations: Adding a new entity to the schema but regenerating only the DAO class, not the DaoSession/DaoMaster; mixing generated classes from two schema versions; querying with a subclass class literal.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


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

Appendix: source

Thrown at DaoCore/src/main/java/org/greenrobot/greendao/AbstractDaoSession.java:141

    /** Convenient call for {@link AbstractDao#queryRaw(String, String...)}. */
    public <T, K> List<T> queryRaw(Class<T> entityClass, String where, String... selectionArgs) {
        @SuppressWarnings("unchecked")
        AbstractDao<T, K> dao = (AbstractDao<T, K>) getDao(entityClass);
        return dao.queryRaw(where, selectionArgs);
    }

    /** Convenient call for {@link AbstractDao#queryBuilder()}. */
    public <T> QueryBuilder<T> queryBuilder(Class<T> entityClass) {
        @SuppressWarnings("unchecked")
        AbstractDao<T, ?> dao = (AbstractDao<T, ?>) getDao(entityClass);
        return dao.queryBuilder();
    }

    public AbstractDao<?, ?> getDao(Class<? extends Object> entityClass) {
        AbstractDao<?, ?> dao = entityToDao.get(entityClass);
        if (dao == null) {
            throw new DaoException("No DAO registered for " + entityClass);
        }
        return dao;
    }

    /**
     * Run the given Runnable inside a database transaction. If you except a result, consider callInTx.
     */
    public void runInTx(Runnable runnable) {
        db.beginTransaction();
        try {
            runnable.run();
            db.setTransactionSuccessful();
        } finally {
            db.endTransaction();
        }
    }

    /**

View on GitHub (pinned to 0bbb338e17)