{"record":{"id":"81fdd982ad7c6b91","repo":"hibernate/hibernate-orm","slug":"error-performing-isolated-work","errorCode":null,"errorMessage":"Error performing isolated work","messagePattern":"Error performing isolated work","errorType":"exception","errorClass":"HibernateException","httpStatus":null,"severity":"critical","filePath":"hibernate-core/src/main/java/org/hibernate/resource/transaction/backend/jdbc/internal/JdbcIsolationDelegate.java","lineNumber":75,"sourceCode":"\t\t\t\twasAutoCommit = disableAutoCommit( transacted, connection );\n\t\t\t}\n\t\t\tcatch (SQLException sqle) {\n\t\t\t\tthrow sqlExceptionHelper.convert( sqle, \"Unable to manage autocommit on isolated JDBC connection\" );\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\treturn doWorkAndCommit( work, transacted, connection );\n\t\t\t}\n\t\t\tcatch (Exception exception) {\n\t\t\t\trollBack( transacted, connection, exception );\n\t\t\t\tif ( exception instanceof HibernateException he ) {\n\t\t\t\t\tthrow he;\n\t\t\t\t}\n\t\t\t\telse if ( exception instanceof SQLException sqle ) {\n\t\t\t\t\tthrow sqlExceptionHelper.convert( sqle, \"Error performing isolated work\" );\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tthrow new HibernateException( \"Error performing isolated work\", exception );\n\t\t\t\t}\n\t\t\t}\n\t\t\tfinally {\n\t\t\t\tresetAutoCommit( transacted, wasAutoCommit, connection );\n\t\t\t}\n\t\t}\n\t\tfinally {\n\t\t\treleaseConnection( connection );\n\t\t}\n\t}\n\n\tprivate static <T> T doWorkAndCommit(WorkExecutorVisitable<T> work, boolean transacted, Connection connection)\n\t\t\tthrows SQLException {\n\t\tT result = work.accept( new WorkExecutor<>(), connection );\n\t\tif ( transacted ) {\n\t\t\tconnection.commit();\n\t\t}\n\t\treturn result;","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/resource/transaction/backend/jdbc/internal/JdbcIsolationDelegate.java#L57-L93","documentation":"HibernateException from JdbcIsolationDelegate: work executed in its own isolated JDBC transaction — separate from the current one — failed with a SQLException that the SqlExceptionHelper converted with this generic message. This delegate backs isolated internal work such as table-based ID generator segment reads, sequence information extraction, and similar single-shot database helper operations.","triggerScenarios":"An entity uses a table-based generator (or another component that runs isolated work) and the isolated SELECT/UPDATE fails: the generator table or sequence does not exist, the DB user lacks privileges on it, the mapping names the wrong table/sequence, or the isolated connection itself cannot reach the DB. Typically surfaces on the first insert after startup.","commonSituations":"Schema created without hibernate_sequence / the @TableGenerator table; @TableGenerator pointing at a wrong table or pkColumn/valueColumn names; migrations that renamed sequences (Oracle/PostgreSQL); read-restricted DB users missing SELECT/UPDATE grants on the generator object.","solutions":["Read the converted cause (SQLException + actual SQL) to see exactly which statement and object failed","Create or fix the backing object: e.g. CREATE TABLE for the @TableGenerator table (with its pk/value columns and seed row) or CREATE SEQUENCE hibernate_sequence","Grant the DB user the needed privileges on that object","Validate the mapping against the schema: table/sequence names, pkColumnName/valueColumnName, allocationSize"],"exampleFix":"// before\n@TableGenerator(name = \"ids\", table = \"gen_table\", pkColumnName = \"k\", valueColumnName = \"v\")\n// gen_table never created -> 'Error performing isolated work' on first persist\n\n// after\n// migration (run once):\n// CREATE TABLE gen_table (k VARCHAR(64) PRIMARY KEY, v BIGINT NOT NULL);\n// INSERT INTO gen_table (k, v) VALUES ('ids', 0);","handlingStrategy":"try-catch","validationCode":"// PostgreSQL: verify the generator object exists before the first insert\ntry (Connection c = dataSource.getConnection();\n     PreparedStatement ps = c.prepareStatement(\n         \"select 1 from information_schema.sequences where sequence_name = 'hibernate_sequence'\")) {\n  if (!ps.executeQuery().next()) {\n    throw new IllegalStateException(\"hibernate_sequence is missing\");\n  }\n}","typeGuard":"static SQLException findSqlException(Throwable t) {\n  for (Throwable c = t; c != null; c = c.getCause()) {\n    if (c instanceof SQLException s) return s;\n  }\n  return null;\n}","tryCatchPattern":"try {\n  em.persist(entity);\n  em.flush();\n} catch (org.hibernate.HibernateException e) {\n  SQLException sql = findSqlException(e); // 'Error performing isolated work'\n  // inspect sql + statement, then fix the schema object (create/grant) rather than retrying blindly\n}","preventionTips":["Run hibernate.hbm2ddl.auto=validate at startup so missing generator objects fail fast","Keep migrations in sync with @TableGenerator/@SequenceGenerator mappings","Grant SELECT/UPDATE on generator tables to the application DB user explicitly"],"tags":["hibernate","id-generation","table-generator","sequence","jdbc"],"backgroundTag":"jdbc-sql-execution-failed","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}