Spring boot ddl auto generator
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
Spring Boot can delegate schema management to Hibernate through the spring.jpa.hibernate.ddl-auto property. That setting is convenient during development, but it is easy to misuse because each mode has very different consequences for data safety and deployment discipline.
What ddl-auto Controls
ddl-auto tells Hibernate what to do when the application starts with respect to the database schema derived from your entity mappings.
The common values are:
- '
noneor leaving it unset, meaning Hibernate does not manage the schema' - '
validate, meaning Hibernate checks that the schema matches the entities' - '
update, meaning Hibernate tries to apply incremental schema changes' - '
create, meaning Hibernate drops and recreates the schema at startup' - '
create-drop, meaning Hibernate creates the schema at startup and drops it again on shutdown'
Those modes are not interchangeable. Choosing the wrong one can destroy data or hide migration problems.
Example Configuration
In application.properties, the setting looks like this:
The YAML version is equivalent.
A simple entity might look like this:
Hibernate reads metadata such as @Table, @Column, and the identifier strategy when deciding what schema shape it expects.
Which Mode Fits Which Environment
For local prototyping, update can be convenient because it lets entity changes appear in the schema without hand-written SQL every time.
For tests, create-drop is often useful because each run starts from a clean schema and leaves no leftovers behind.
For production, validate is usually the safe default. It lets the application fail fast if the schema and entity mappings drift apart, while keeping actual schema changes under explicit migration control.
That is why many teams pair Spring Boot with Flyway or Liquibase:
- migrations make schema evolution explicit and reviewable
- '
validateconfirms the deployed schema still matches the code'
This combination is much safer than trusting automatic updates in environments that hold real data.
Why update Is Convenient but Risky
update sounds appealing because it promises incremental evolution, but it is not a full migration system. It may handle some additions cleanly, yet it does not give you the same control over renames, data backfills, or complex transformations.
If a column rename is interpreted as "drop one column and add another," you can lose data or end up with a schema that no longer matches the intended rollout plan.
So the right mental model is: update is a development convenience, not a production migration strategy.
Common Pitfalls
Using create or create-drop against a database with important data is the most dangerous mistake because those modes rebuild the schema.
Relying on update in production is another common problem. It can mask schema-management gaps until a harder migration appears.
Forgetting that entity annotations influence schema validation also causes confusion. If the entity says nullable = false but the database says otherwise, validate can legitimately fail.
Finally, do not assume Hibernate-generated DDL will always match the exact operational choices you want for indexing, constraints, or naming. Explicit migrations give you more control.
Summary
- '
spring.jpa.hibernate.ddl-autocontrols how Hibernate interacts with the database schema at startup' - '
validateis usually the safest production choice when migrations are managed separately' - '
updateis useful for development but is not a substitute for real migration tooling' - '
createandcreate-dropare destructive and belong only in disposable environments' - Flyway or Liquibase plus
validateis a strong default for disciplined schema management
Related reading
- Spring Boot default H2 jdbc connection and H2 console
- Spring boot doesn't load data to initialize database using data.sql
- Spring boot fails to load DataSource using PostgreSQL driver
- Spring Boot Getting Scheduled cron value from database
- Spring Boot default proxying mechanism
- Spring Boot default test throws an IllegalStateException
- Spring Boot Hibernate and Flyway boot order
- Spring Boot JPA2 Hibernate - enable second level cache

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.