{"record":{"id":"eff2d603df4ca141","repo":"hibernate/hibernate-orm","slug":"schema-validation-sequence-s-defined-inconsist","errorCode":null,"errorMessage":"Schema validation: sequence [%s] defined inconsistent increment-size; found [%s] but expecting [%s]","messagePattern":"Schema validation: sequence \\[(.+?)\\] defined inconsistent increment-size; found \\[(.+?)\\] but expecting \\[(.+?)\\]","errorType":"exception","errorClass":"SchemaManagementException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/tool/schema/internal/AbstractSchemaValidator.java","lineNumber":319,"sourceCode":"\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}\n","sourceCodeStart":301,"sourceCodeEnd":330,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/AbstractSchemaValidator.java#L301-L330","documentation":"Sequence validation found the sequence but its INCREMENT BY differs from the entity's increment size (JPA allocationSize, default 50 with pooled optimizers): found [<db increment>] but expecting [<allocationSize>]. With pooled allocation, a mismatch would produce duplicate or gapped IDs, so validation rejects the combination. The check only runs when the database reports a positive increment value.","triggerScenarios":"validate where @SequenceGenerator omits allocationSize (JPA default 50) against a sequence created with INCREMENT BY 1 (the usual manual CREATE SEQUENCE default); or a migration created INCREMENT BY 50 and the mapping later set allocationSize = 1; or the sequence is shared with legacy code that expects increment 1.","commonSituations":"The classic Hibernate + PostgreSQL case: hand-written sequence with INCREMENT 1, entity relying on default allocationSize 50; switching between pooled/pooled-lo optimizers; upgrading between Hibernate major versions when default optimizer selection changed; DBA-tuned sequences.","solutions":["Set allocationSize on the generator to match the physical sequence: @SequenceGenerator(..., allocationSize = 1).","Or change the database sequence: ALTER SEQUENCE <seq> INCREMENT BY <allocationSize>;","Remember allocationSize = 1 disables pooling (interleaved-safe); any pool size > 1 requires the sequence increment to equal it exactly.","Keep the chosen combination in a migration + mapping review so both sides never drift again."],"exampleFix":"// before: allocationSize defaults to 50 while the sequence increments by 1\n@SequenceGenerator(name = \"order_seq\", sequenceName = \"order_seq\")\n\n// after: match the physical sequence (or ALTER SEQUENCE order_seq INCREMENT BY 50)\n@SequenceGenerator(name = \"order_seq\", sequenceName = \"order_seq\", allocationSize = 1)","handlingStrategy":"validation","validationCode":"// Before validate, check the physical sequence increment matches allocationSize\ntry (Connection c = dataSource.getConnection();\n     PreparedStatement ps = c.prepareStatement(\n             \"SELECT increment FROM information_schema.sequences WHERE sequence_name = ?\")) {\n    ps.setString(1, \"order_seq\");\n    try (ResultSet rs = ps.executeQuery()) {\n        if (rs.next() && rs.getInt(1) != 1) { // allocationSize = 1 in this app\n            throw new IllegalStateException(\"order_seq increment \" + rs.getInt(1) + \" != allocationSize 1\");\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(\"inconsistent increment-size\")) {\n        // message shows found vs expecting: set allocationSize accordingly or ALTER SEQUENCE ... INCREMENT BY\n    }\n    throw e;\n}","preventionTips":["Always set allocationSize explicitly on @SequenceGenerator instead of relying on the JPA default 50","Create sequences with INCREMENT BY exactly equal to the mapped allocationSize","Never share a sequence between pooled Hibernate allocation and increment-1 consumers"],"tags":["hibernate","schema-validation","sequence","id-generation","hbm2ddl"],"backgroundTag":"sequence-increment-mismatch","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}