hibernate/hibernate-orm · error · SchemaManagementException

Schema validation: missing sequence [%s]

Error message

Schema validation: missing sequence [%s]

What it means

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.

Source

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

				}
			}

			if ( !matches ) {
				throw new SchemaManagementException(
						String.format(
								ROOT,
								"Unique-key mismatch - `%s` on table `%s`",
								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. Create the missing sequence with the mapped name: CREATE SEQUENCE order_seq START WITH 1 INCREMENT BY <allocationSize>;
  2. Align sequenceName (and schema qualification) in @SequenceGenerator with the sequence that actually exists.
  3. Ensure migrations include sequence DDL and run before validation in every environment.
  4. On databases without sequences, switch the generator to IDENTITY/TABLE (or a dialect-appropriate strategy).

Example fix

-- before: entity expects order_seq (allocationSize 50) but the database has no such sequence
-- @SequenceGenerator(name = "order_seq", sequenceName = "order_seq", allocationSize = 50)

-- after: create it with a matching increment
CREATE SEQUENCE order_seq START WITH 1 INCREMENT BY 50;
Defensive patterns

Strategy: validation

Validate before calling

// Before validate, confirm every mapped sequence exists (and its increment matches)
try (Connection c = dataSource.getConnection()) {
    DatabaseMetaData md = c.getMetaData();
    try (ResultSet rs = md.getTables(null, null, "order_seq", new String[]{"SEQUENCE"})) {
        // portable enough for a smoke check on most drivers; alternatively query information_schema.sequences
        if (!rs.next()) {
            throw new IllegalStateException("order_seq missing - create it before validate");
        }
    }
}

Try / catch

try {
    new SchemaValidator().validate(metadata, serviceRegistry);
} catch (SchemaManagementException e) {
    if (e.getMessage() != null && e.getMessage().contains("missing sequence")) {
        // create the sequence with matching name/schema/increment, or align sequenceName in the generator
    }
    throw e;
}

Prevention

When it happens

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

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

Related errors


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