hibernate/hibernate-orm · error · PersistenceException

Error performing schema management [persistence unit: {}]

Error message

Error performing schema management  [persistence unit: {}] 

What it means

Thrown by EntityManagerFactoryBuilderImpl.generateSchema() as a PersistenceException when SchemaManagementToolCoordinator.process() fails while performing schema management (create/drop/update/validate) for a JPA persistence unit. The real cause is always in the wrapped exception - Hibernate rethrows it only to add the persistence-unit context. It fires during JPA schema generation (jakarta.persistence.schema-generation.* properties) rather than normal EntityManagerFactory startup.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/jpa/boot/internal/EntityManagerFactoryBuilderImpl.java:1627

			final var binding = serviceRegistry.locateServiceBinding( ConnectionProvider.class );
			if ( binding != null && binding.getService() instanceof Stoppable ) {
				lifecycleOwner.stopService( binding );
				binding.setService( null );
			}
		}
	}

	@Override
	public void generateSchema() {
		// This seems overkill, but building the SF is necessary to get the
		// Integrators to kick in. Metamodel will clean this up...
		try {
			populateSessionFactoryBuilder();
			SchemaManagementToolCoordinator.process( metadata, standardServiceRegistry,
					configurationValues, DelayedDropRegistryNotAvailableImpl.INSTANCE );
		}
		catch (Exception e) {
			throw new PersistenceException( "Error performing schema management " + exceptionHeader(), e );
		}
		finally {
			// release this builder
			cancel();
		}
	}

	@Override
	public EntityManagerFactory build() {
		boolean success = false;
		try {
			final var sessionFactoryBuilder = populateSessionFactoryBuilder();
			try {
				final var entityManagerFactory = sessionFactoryBuilder.build();
				success = true;
				return entityManagerFactory;
			}
			catch (Exception e) {

View on GitHub (pinned to fad1729dce)

Solutions

  1. Read the nested cause of the PersistenceException - it names the failing DDL statement or connection problem; fix that first.
  2. Verify JDBC connectivity and credentials for the target datasource before enabling schema generation.
  3. If validating, align mappings with the actual schema (or recreate the schema) so validate stops reporting differences.
  4. Grant the DB user CREATE/ALTER/REFERENCES privileges, or switch to a migrations tool (Flyway/Liquibase) with jakarta.persistence.schema-generation.database.action=none.
  5. Set hibernate.hbm2ddl.auto / the schema-generation action to 'none' in production to avoid destructive drop statements.

Example fix

// before
<property name="jakarta.persistence.schema-generation.database.action" value="drop-and-create"/>

// after (validate locally, use Flyway/Liquibase for real environments)
<property name="jakarta.persistence.schema-generation.database.action" value="none"/>
Defensive patterns

Strategy: try-catch

Validate before calling

// before enabling schema management, verify the target schema metadata is reachable
try (Connection c = dataSource.getConnection(); ResultSet rs = c.getMetaData().getTables(null, null, "MY_ENTITY", null)) {
    // proceed with schema generation only after sanity-checking connectivity
} catch (SQLException e) { throw new IllegalStateException("DB unreachable, skip schema generation", e); }

Try / catch

try {
    builder.generateSchema();
} catch (PersistenceException e) {
    Throwable cause = e.getCause() instanceof PersistenceException p ? p.getCause() : e.getCause();
    log.error("Schema management failed: {}", cause.getMessage());
    throw e; // never retry DDL blindly - drop/create is not idempotent-safe under partial failure
}

Prevention

When it happens

Trigger: Calling generateSchema() on the builder (or letting the container run schema generation via jakarta.persistence.schema-generation.database.action=create/create-drop/drop-and-create) when the configured SchemaMigrator/SchemaValidator/SchemaCreator fails: bad JDBC URL, dialect cannot be resolved, SQL type mismatch on validate, missing DDL permissions, or naming strategy producing invalid identifiers.

Common situations: persistence.xml with <property name="jakarta.persistence.schema-generation.database.action" value="update"/> against a schema that has drifted; running schema generation with a user lacking CREATE/ALTER privileges; dialect autodetection failing because the connection is down; validating against an old schema after a model change.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


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