๐ด The Error You're Seeing
Confirm this matches your console output. If it does, you're in the right place.
2026-02-18 13:15:20.100 ERROR 8842 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' ... nested exception is org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: missing table [users]
OR
org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "USERS" already exists; SQL statement:
CREATE TABLE users (id BIGINT NOT NULL, name VARCHAR(255), PRIMARY KEY (id)) [42101-214]โก Quick Fix Works 80% of the time
Change spring.jpa.hibernate.ddl-auto to 'update' or 'none' instead of 'create'.
# application.properties
spring.jpa.hibernate.ddl-auto=update๐ง Why this Happens
Tap to expand the deep technical explanation
You have configured Hibernate to generate tables (e.g., `ddl-auto=create` or `create-drop`), but you also have a `schema.sql` file in your `src/main/resources` that tries to create the exact same table. The database rejects the second creation attempt.
The HITEC City Parking Spot Analogy:
It's like a builder laying the foundation for a house, but the architect also hired a second builder to lay the exact same foundation. The second builder hits concrete and says, 'This already exists!'
๐ How to Reproduce Confirm this is your error
Add a `schema.sql` file with `CREATE TABLE users (...);`. Set `spring.jpa.hibernate.ddl-auto=create`. Run the Spring Boot app with an H2 database.
๐ ๏ธ Solutions (5 Ways to Fix)
Change ddl-auto to 'update'
๐ Use this as the general development setting.
Hibernate will only create the table if it doesn't exist, and will alter it if the Entity changes. It won't try to recreate it every time.
# application.properties
spring.jpa.hibernate.ddl-auto=updateDisable schema.sql execution
๐ Use this if you want Hibernate to handle all table creation and you don't need `schema.sql`.
Tell Spring Boot not to run your SQL initialization scripts.
# application.properties
spring.sql.init.mode=neverUse 'create-drop' ONLY for fresh tests
๐ Use this in `application-test.properties` for integration tests.
`create-drop` drops tables on shutdown and recreates them on startup. It ensures a clean slate but fails if `schema.sql` also runs.
# src/test/resources/application-test.properties
spring.jpa.hibernate.ddl-auto=create-drop
spring.sql.init.mode=neverAdd 'IF NOT EXISTS' to schema.sql
๐ Use this if you must use both Hibernate and `schema.sql`.
Modify your SQL script to ignore errors if the table is already present.
-- src/main/resources/schema.sql
CREATE TABLE IF NOT EXISTS users (
id BIGINT PRIMARY KEY,
name VARCHAR(255)
);Defer DataSource Initialization
๐ Use this if you are on Spring Boot 3 and `schema.sql` runs before Hibernate creates tables.
In Spring Boot 3, `schema.sql` runs before Hibernate by default. This property reverses the order so Hibernate creates the tables first, then `schema.sql` inserts data.
# application.properties
spring.jpa.defer-datasource-initialization=true๐ Version Notes
`schema.sql` runs before Hibernate. `spring.sql.init.mode` defaults to `embedded`.
Requires `spring.jpa.defer-datasource-initialization=true` if using `schema.sql` with `ddl-auto`.
๐ก๏ธ How to Prevent This Next Time
Choose ONE source of truth for your schema. Either let Hibernate manage it (`ddl-auto=update`) OR use Flyway/Liquibase. Don't mix `ddl-auto=create` with `schema.sql`.