{"record":{"id":"cf980d0995b894be","repo":"hibernate/hibernate-orm","slug":"schema-validation-missing-sequence-s","errorCode":null,"errorMessage":"Schema validation: missing sequence [%s]","messagePattern":"Schema validation: missing sequence \\[(.+?)\\]","errorType":"exception","errorClass":"SchemaManagementException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/tool/schema/internal/AbstractSchemaValidator.java","lineNumber":311,"sourceCode":"\t\t\t\t}\n\t\t\t}\n\n\t\t\tif ( !matches ) {\n\t\t\t\tthrow new SchemaManagementException(\n\t\t\t\t\t\tString.format(\n\t\t\t\t\t\t\t\tROOT,\n\t\t\t\t\t\t\t\t\"Unique-key mismatch - `%s` on table `%s`\",\n\t\t\t\t\t\t\t\tname.render( dialect ),\n\t\t\t\t\t\t\t\ttableInformation.getName().render()\n\t\t\t\t\t\t)\n\t\t\t\t);\n\t\t\t}\n\t\t} );\n\t}\n\n\tprotected void validateSequence(Sequence sequence, SequenceInformation sequenceInformation) {\n\t\tif ( sequenceInformation == null ) {\n\t\t\tthrow new SchemaManagementException(\n\t\t\t\t\tString.format( \"Schema validation: missing sequence [%s]\", sequence.getName() )\n\t\t\t);\n\t\t}\n\n\t\tfinal Number incrementValue = sequenceInformation.getIncrementValue();\n\t\tif ( incrementValue != null && incrementValue.intValue() > 0\n\t\t\t\t&& sequence.getIncrementSize() != incrementValue.intValue() ) {\n\t\t\tthrow new SchemaManagementException(\n\t\t\t\t\tString.format(\n\t\t\t\t\t\t\t\"Schema validation: sequence [%s] defined inconsistent increment-size; found [%s] but expecting [%s]\",\n\t\t\t\t\t\t\tsequence.getName(),\n\t\t\t\t\t\t\tincrementValue,\n\t\t\t\t\t\t\tsequence.getIncrementSize()\n\t\t\t\t\t)\n\t\t\t);\n\t\t}\n\t}\n}","sourceCodeStart":293,"sourceCodeEnd":329,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/AbstractSchemaValidator.java#L293-L329","documentation":"Sequence validation: the mapping defines an ID sequence (@SequenceGenerator / <sequence/>) but no SequenceInformation was found in JDBC metadata for that name - the database has no such sequence. Validation aborts because the ID generator would fail at runtime anyway, so Hibernate refuses to start.","triggerScenarios":"hibernate.hbm2ddl.auto=validate with @GeneratedValue(strategy = SEQUENCE) plus a generator whose sequenceName has no CREATE SEQUENCE counterpart in the database: migrations created tables but not sequences; the sequence lives in another schema (default_schema/qualification mismatch); the sequence name differs in case/quoting; the target database does not support sequences at all (MySQL before sequence support), so a sequence strategy cannot work.","commonSituations":"Fresh environments where only table DDL was migrated; switching from IDENTITY to SEQUENCE generators without shipping sequence DDL; PostgreSQL schema-qualified names (public.order_seq vs order_seq); H2 vs Postgres name handling; running validate before the migration step in CI.","solutions":["Create the missing sequence with the mapped name: CREATE SEQUENCE order_seq START WITH 1 INCREMENT BY <allocationSize>;","Align sequenceName (and schema qualification) in @SequenceGenerator with the sequence that actually exists.","Ensure migrations include sequence DDL and run before validation in every environment.","On databases without sequences, switch the generator to IDENTITY/TABLE (or a dialect-appropriate strategy)."],"exampleFix":"-- before: entity expects order_seq (allocationSize 50) but the database has no such sequence\n-- @SequenceGenerator(name = \"order_seq\", sequenceName = \"order_seq\", allocationSize = 50)\n\n-- after: create it with a matching increment\nCREATE SEQUENCE order_seq START WITH 1 INCREMENT BY 50;","handlingStrategy":"validation","validationCode":"// Before validate, confirm every mapped sequence exists (and its increment matches)\ntry (Connection c = dataSource.getConnection()) {\n    DatabaseMetaData md = c.getMetaData();\n    try (ResultSet rs = md.getTables(null, null, \"order_seq\", new String[]{\"SEQUENCE\"})) {\n        // portable enough for a smoke check on most drivers; alternatively query information_schema.sequences\n        if (!rs.next()) {\n            throw new IllegalStateException(\"order_seq missing - create it before validate\");\n        }\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    new SchemaValidator().validate(metadata, serviceRegistry);\n} catch (SchemaManagementException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"missing sequence\")) {\n        // create the sequence with matching name/schema/increment, or align sequenceName in the generator\n    }\n    throw e;\n}","preventionTips":["Include CREATE SEQUENCE statements in the same migration set as table DDL","Qualify sequence names explicitly (schema + name) when the default schema is ambiguous","On databases without sequences, use a supported strategy (IDENTITY/TABLE) instead"],"tags":["hibernate","schema-validation","sequence","hbm2ddl","id-generation"],"backgroundTag":"missing-sequence","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}