{"record":{"id":"fa1385c4eafe4c7f","repo":"hibernate/hibernate-orm","slug":"error-performing-schema-management-persistence-u","errorCode":null,"errorMessage":"Error performing schema management  [persistence unit: {}] ","messagePattern":"Error performing schema management  \\[persistence unit: (.+?)\\] ","errorType":"exception","errorClass":"PersistenceException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/jpa/boot/internal/EntityManagerFactoryBuilderImpl.java","lineNumber":1627,"sourceCode":"\t\t\tfinal var binding = serviceRegistry.locateServiceBinding( ConnectionProvider.class );\n\t\t\tif ( binding != null && binding.getService() instanceof Stoppable ) {\n\t\t\t\tlifecycleOwner.stopService( binding );\n\t\t\t\tbinding.setService( null );\n\t\t\t}\n\t\t}\n\t}\n\n\t@Override\n\tpublic void generateSchema() {\n\t\t// This seems overkill, but building the SF is necessary to get the\n\t\t// Integrators to kick in. Metamodel will clean this up...\n\t\ttry {\n\t\t\tpopulateSessionFactoryBuilder();\n\t\t\tSchemaManagementToolCoordinator.process( metadata, standardServiceRegistry,\n\t\t\t\t\tconfigurationValues, DelayedDropRegistryNotAvailableImpl.INSTANCE );\n\t\t}\n\t\tcatch (Exception e) {\n\t\t\tthrow new PersistenceException( \"Error performing schema management \" + exceptionHeader(), e );\n\t\t}\n\t\tfinally {\n\t\t\t// release this builder\n\t\t\tcancel();\n\t\t}\n\t}\n\n\t@Override\n\tpublic EntityManagerFactory build() {\n\t\tboolean success = false;\n\t\ttry {\n\t\t\tfinal var sessionFactoryBuilder = populateSessionFactoryBuilder();\n\t\t\ttry {\n\t\t\t\tfinal var entityManagerFactory = sessionFactoryBuilder.build();\n\t\t\t\tsuccess = true;\n\t\t\t\treturn entityManagerFactory;\n\t\t\t}\n\t\t\tcatch (Exception e) {","sourceCodeStart":1609,"sourceCodeEnd":1645,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/jpa/boot/internal/EntityManagerFactoryBuilderImpl.java#L1609-L1645","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Read the nested cause of the PersistenceException - it names the failing DDL statement or connection problem; fix that first.","Verify JDBC connectivity and credentials for the target datasource before enabling schema generation.","If validating, align mappings with the actual schema (or recreate the schema) so validate stops reporting differences.","Grant the DB user CREATE/ALTER/REFERENCES privileges, or switch to a migrations tool (Flyway/Liquibase) with jakarta.persistence.schema-generation.database.action=none.","Set hibernate.hbm2ddl.auto / the schema-generation action to 'none' in production to avoid destructive drop statements."],"exampleFix":"// before\n<property name=\"jakarta.persistence.schema-generation.database.action\" value=\"drop-and-create\"/>\n\n// after (validate locally, use Flyway/Liquibase for real environments)\n<property name=\"jakarta.persistence.schema-generation.database.action\" value=\"none\"/>","handlingStrategy":"try-catch","validationCode":"// before enabling schema management, verify the target schema metadata is reachable\ntry (Connection c = dataSource.getConnection(); ResultSet rs = c.getMetaData().getTables(null, null, \"MY_ENTITY\", null)) {\n    // proceed with schema generation only after sanity-checking connectivity\n} catch (SQLException e) { throw new IllegalStateException(\"DB unreachable, skip schema generation\", e); }","typeGuard":null,"tryCatchPattern":"try {\n    builder.generateSchema();\n} catch (PersistenceException e) {\n    Throwable cause = e.getCause() instanceof PersistenceException p ? p.getCause() : e.getCause();\n    log.error(\"Schema management failed: {}\", cause.getMessage());\n    throw e; // never retry DDL blindly - drop/create is not idempotent-safe under partial failure\n}","preventionTips":["Never use drop-and-create against production data; reserve it for tests and local dev.","Prefer validate in CI and Flyway/Liquibase for real environments.","Run schema generation with the same DB user/permissions as production to catch DDL grant issues early."],"tags":["hibernate","jpa","schema-management","hbm2ddl","persistence-unit","ddl"],"backgroundTag":"schema-validation-failed","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}