hibernate/hibernate-orm · error · SchemaManagementException

Schema validation: sequence [%s] defined inconsistent increm

Error message

Schema validation: sequence [%s] defined inconsistent increment-size; found [%s] but expecting [%s]

What it means

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.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/tool/schema/internal/AbstractSchemaValidator.java:319

								name.render( dialect ),
								tableInformation.getName().render()
						)
				);
			}
		} );
	}

	protected void validateSequence(Sequence sequence, SequenceInformation sequenceInformation) {
		if ( sequenceInformation == null ) {
			throw new SchemaManagementException(
					String.format( "Schema validation: missing sequence [%s]", sequence.getName() )
			);
		}

		final Number incrementValue = sequenceInformation.getIncrementValue();
		if ( incrementValue != null && incrementValue.intValue() > 0
				&& sequence.getIncrementSize() != incrementValue.intValue() ) {
			throw new SchemaManagementException(
					String.format(
							"Schema validation: sequence [%s] defined inconsistent increment-size; found [%s] but expecting [%s]",
							sequence.getName(),
							incrementValue,
							sequence.getIncrementSize()
					)
			);
		}
	}
}

View on GitHub (pinned to fad1729dce)

Solutions

  1. Set allocationSize on the generator to match the physical sequence: @SequenceGenerator(..., allocationSize = 1).
  2. Or change the database sequence: ALTER SEQUENCE <seq> INCREMENT BY <allocationSize>;
  3. Remember allocationSize = 1 disables pooling (interleaved-safe); any pool size > 1 requires the sequence increment to equal it exactly.
  4. Keep the chosen combination in a migration + mapping review so both sides never drift again.

Example fix

// before: allocationSize defaults to 50 while the sequence increments by 1
@SequenceGenerator(name = "order_seq", sequenceName = "order_seq")

// after: match the physical sequence (or ALTER SEQUENCE order_seq INCREMENT BY 50)
@SequenceGenerator(name = "order_seq", sequenceName = "order_seq", allocationSize = 1)
Defensive patterns

Strategy: validation

Validate before calling

// Before validate, check the physical sequence increment matches allocationSize
try (Connection c = dataSource.getConnection();
     PreparedStatement ps = c.prepareStatement(
             "SELECT increment FROM information_schema.sequences WHERE sequence_name = ?")) {
    ps.setString(1, "order_seq");
    try (ResultSet rs = ps.executeQuery()) {
        if (rs.next() && rs.getInt(1) != 1) { // allocationSize = 1 in this app
            throw new IllegalStateException("order_seq increment " + rs.getInt(1) + " != allocationSize 1");
        }
    }
}

Try / catch

try {
    new SchemaValidator().validate(metadata, serviceRegistry);
} catch (SchemaManagementException e) {
    if (e.getMessage() != null && e.getMessage().contains("inconsistent increment-size")) {
        // message shows found vs expecting: set allocationSize accordingly or ALTER SEQUENCE ... INCREMENT BY
    }
    throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22). Data as JSON: /api/errors/eff2d603df4ca141. Report an issue: GitHub.