{"record":{"id":"b98129f369b072ae","repo":"flowable/flowable-engine","slug":"could-not-set-database-schema-on-connection","errorCode":null,"errorMessage":"Could not set database schema on connection","messagePattern":"Could not set database schema on connection","errorType":"exception","errorClass":"FlowableException","httpStatus":null,"severity":"error","filePath":"modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/db/DbSqlSessionFactory.java","lineNumber":88,"sourceCode":"    protected boolean usePrefixId;\n    \n    public DbSqlSessionFactory(boolean usePrefixId) {\n        this.usePrefixId = usePrefixId;\n    }\n\n    @Override\n    public Class<?> getSessionType() {\n        return DbSqlSession.class;\n    }\n\n    @Override\n    public Session openSession(CommandContext commandContext) {\n        DbSqlSession dbSqlSession = createDbSqlSession();\n        if (getDatabaseSchema() != null && getDatabaseSchema().length() > 0) {\n            try {\n                dbSqlSession.getSqlSession().getConnection().setSchema(getDatabaseSchema());\n            } catch (SQLException e) {\n                throw new FlowableException(\"Could not set database schema on connection\", e);\n            }\n        }\n        if (getDatabaseCatalog() != null && getDatabaseCatalog().length() > 0) {\n            try {\n                dbSqlSession.getSqlSession().getConnection().setCatalog(getDatabaseCatalog());\n            } catch (SQLException e) {\n                throw new FlowableException(\"Could not set database catalog on connection\", e);\n            }\n        }\n        if (dbSqlSession.getSqlSession().getConnection() == null) {\n            throw new FlowableException(\"Invalid dbSqlSession: no active connection found\");\n        }\n        return dbSqlSession;\n    }\n\n    protected DbSqlSession createDbSqlSession() {\n        return new DbSqlSession(this, Context.getCommandContext().getSession(EntityCache.class));\n    }","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/db/DbSqlSessionFactory.java#L70-L106","documentation":"Thrown by DbSqlSessionFactory.openSession when applying the configured database schema to the underlying JDBC connection fails with SQLException; the connection cannot be put into the expected schema, so the persistence session is not usable.","triggerScenarios":"databaseSchema (engine configuration) is set and the underlying connection's setSchema call throws — e.g. driver does not support setSchema, schema does not exist, or the DB user lacks permission to use it.","commonSituations":"Schema name typo or wrong case (Oracle/H2 case sensitivity); schema not created before engine start; drivers with no-op/throwing setSchema implementations; connecting to a database where the user's default schema differs.","solutions":["Verify the schema exists and the DB user has rights: CREATE SCHEMA / GRANT as needed.","Check the schema name spelling and case for your database.","If the driver doesn't support setSchema, prepend the schema to the JDBC URL or leave databaseSchema unset and use fully qualified table prefixes.","Use a current JDBC driver version compatible with your database."],"exampleFix":"// before\n<property name=\"databaseSchema\" value=\"FLOWABLE\" /> // schema missing or unsupported\n// after\n-- run first on the DB\nCREATE SCHEMA FLOWABLE AUTHORIZATION app_user;","handlingStrategy":"try-catch","validationCode":"long cnt = taskService.createTaskQuery().taskId(id).count();\nif (cnt == 0) return; // nothing to delete\nTask fresh = taskService.createTaskQuery().taskId(id).singleResult(); // freshest revision","typeGuard":null,"tryCatchPattern":"try { /* delete entity */ }\ncatch (FlowableOptimisticLockingException e) {\n  // row already deleted or changed: verify state and continue idempotently\n}","preventionTips":["Make deletes idempotent: treat zero-row delete as success when appropriate.","Serialize concurrent deletes of the same row (locking or single-writer paths).","Avoid holding entities across user think-time; reload before deleting.","For async jobs, rely on Flowable's optimistic-locking retry for jobs."],"tags":["database","jdbc","configuration","schema"],"backgroundTag":"database-query-failed","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}