{"record":{"id":"4740f80a50c5d29a","repo":"greenrobot/greenDAO","slug":"callable-failed","errorCode":null,"errorMessage":"Callable failed","messagePattern":"Callable failed","errorType":"exception","errorClass":"DaoException","httpStatus":null,"severity":"error","filePath":"DaoCore/src/main/java/org/greenrobot/greendao/AbstractDaoSession.java","lineNumber":185,"sourceCode":"            db.setTransactionSuccessful();\n            return result;\n        } finally {\n            db.endTransaction();\n        }\n    }\n\n    /**\n     * Like {@link #callInTx(Callable)} but does not require Exception handling (rethrows an Exception as a runtime\n     * DaoException).\n     */\n    public <V> V callInTxNoException(Callable<V> callable) {\n        db.beginTransaction();\n        try {\n            V result;\n            try {\n                result = callable.call();\n            } catch (Exception e) {\n                throw new DaoException(\"Callable failed\", e);\n            }\n            db.setTransactionSuccessful();\n            return result;\n        } finally {\n            db.endTransaction();\n        }\n    }\n\n    /** Gets the Database for custom database access. Not needed for greenDAO entities. */\n    public Database getDatabase() {\n        return db;\n    }\n\n    /** Allows to inspect the meta model using DAOs (e.g. querying table names or properties). */\n    public Collection<AbstractDao<?, ?>> getAllDaos() {\n        return Collections.unmodifiableCollection(entityToDao.values());\n    }\n","sourceCodeStart":167,"sourceCodeEnd":203,"githubUrl":"https://github.com/greenrobot/greenDAO/blob/0bbb338e17c4cf28aba5aae62d42f73f50186157/DaoCore/src/main/java/org/greenrobot/greendao/AbstractDaoSession.java#L167-L203","documentation":"callInTxNoException wraps any Exception thrown by the user-supplied Callable inside a DaoException with message \"Callable failed\" while the database transaction is still open (it is then rolled back by the finally/endTransaction). The original exception is the cause. This lets greendao normalize arbitrary callable failures into its own exception type.","triggerScenarios":"Any Exception thrown from the Callable passed to daoSession.callInTxNoException(callable): null pointer inside the callable, DAO insert/update failures wrapped as RuntimeException, or application-level validation exceptions thrown deliberately by the callable.","commonSituations":"Developers do bulk inserts/updates in a transaction and one entity violates a constraint or NPEs; the wrapped DaoException surfaces after the transaction is rolled back, often confusing them because the root cause is nested.","solutions":["Read getCause() of the DaoException to find the real exception thrown inside the callable and fix that root problem.","Make the callable null-safe: validate entity objects, field values, and any external inputs before calling them.","Move expensive validation before the transaction so only fail-safe DB writes remain inside the callable.","If you need to handle failures yourself, catch DaoException around callInTxNoException instead of throwing inside the callable."],"exampleFix":"// before\ndaos.callInTxNoException(() -> {\n    order.setCustomer(customer.getId()); // NPE if customer is null\n    return orderDao.insert(order);\n});\n// after\nif (customer == null) throw new IllegalArgumentException(\"customer required\");\ndaos.callInTxNoException(() -> {\n    order.setCustomer(customer.getId());\n    return orderDao.insert(order);\n});","handlingStrategy":"try-catch","validationCode":"if (order == null || customer == null) {\n    throw new IllegalArgumentException(\"order and customer must be non-null before tx\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    result = daoSession.callInTxNoException(myCallable);\n} catch (DaoException e) {\n    Throwable cause = e.getCause(); // real failure inside the callable\n    log.severe(\"tx callable failed: \" + cause);\n}","preventionTips":["Validate all inputs and entities before entering the transaction","Always inspect DaoException.getCause() — the message 'Callable failed' is only a wrapper","Keep the callable small and free of business-logic throws"],"tags":["database","transaction","callable"],"backgroundTag":"database-write-failed","analyzedSha":"0bbb338e17c4cf28aba5aae62d42f73f50186157","analyzedAt":"2026-09-08T03:22:36.050Z","contentChangedAt":"2026-09-08T03:22:36.050Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}