How to Fix Spring Boot JPA Table Not Created Automatically

One of the most common issues developers encounter when using Spring Boot with JPA is:

“Tables are not being created automatically by Hibernate.”

You expect Hibernate to generate tables based on your entities —
but nothing happens.

In this production-grade guide, you will learn:

  • Why this problem happens
  • The exact root causes
  • How to diagnose it
  • How to fix it reliably in development and production
  • Best practices for database schema management

This post is written for beginners, intermediate developers, and architects building real apps.

What Does “JPA Table Not Created” Mean?

Spring Boot uses Spring Data JPA with Hibernate by default to interact with relational databases.
Hibernate can auto-generate tables for your entities if configured correctly.

However, this feature relies on multiple factors being configured correctly.
If any condition fails — no tables are created.

How Spring Boot Configures JPA Table Creation

Spring Boot uses the spring.jpa.hibernate.ddl-auto property to control table schema behavior.

Typical values:

  • create → Creates schema, drops on shutdown
  • create-drop → Creates on startup, drops on shutdown
  • update → Attempts to update existing schema
  • validate → Validates schema matches entities
  • none → No automatic schema action

Example configuration:

spring.jpa.hibernate.ddl-auto=update

This tells Hibernate to update your tables based on entity definitions.

For a deep dive into Spring Boot configuration loading order and profiles:
https://springbootfixes.com/spring-boot-configuration-loading-order-production-guide/

Common Causes & Solutions

1. Incorrect DDL-AUTO Setting

This is the most common reason.

If you use:

spring.jpa.hibernate.ddl-auto=none

or didn’t set the property at all, Hibernate may default to no schema action.

Solution

Set a correct value:

spring.jpa.hibernate.ddl-auto=update

For development:

spring.jpa.hibernate.ddl-auto=create

For production, prefer:

  • validate
  • Robust migrations (Flyway/Liquibase)

2. Entity Classes Not Being Scanned

Spring Boot scans entities in the same package as the main application class or below.

If your entity is outside those packages, Hibernate will not see it.

Example wrong structure:

com.example.demo
└── config
└── entities (not scanned automatically)
Solution

Make sure your main class is at the root:

com.example.app
├── DemoApplication
├── controller
├── service
└── model (entities here)

Or explicitly specify:

@SpringBootApplication(scanBasePackages = { "com.example" })

3. Missing Database Privileges

In production, your database user might not have CREATE or ALTER privileges.

When Spring Boot attempts schema generation, it fails silently (or logs permission errors).

Solution

Ensure your database user has appropriate privileges:

GRANT CREATE, ALTER, SELECT, INSERT, UPDATE, DELETE ON mydb.* TO 'appuser';

4. Using an Embedded Database in Dev but Not in Prod

In local dev, you may rely on embedded databases like H2:

spring.datasource.url=jdbc:h2:mem:testdb
spring.jpa.hibernate.ddl-auto=create

This works locally — but in production you might be using MySQL/PostgreSQL with completely different settings.

Solution

Match your profile configs and verify environment properties:

  • application-dev.yml
  • application-prod.yml

Active profile:

SPRING_PROFILES_ACTIVE=prod

See how profiles affect configuration:
https://springbootfixes.com/spring-boot-configuration-and-profiles-explained-beginner-to-production-guide/

5. Reserved Keywords or Invalid Table Names

Some database engines reserve certain words (e.g., user, order). Hibernate may silently skip table creation when such names are used.

Solution

Use explicit table names:

@Entity
@Table(name = "app_user")
public class User {}

How to Diagnose the Real Cause

Enable SQL Logging

SQL logs show what Hibernate is doing on startup:

spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true

This helps verify whether Hibernate is executing DDL commands.

Database Metadata Tools

Use database clients (DBeaver, MySQL Workbench) to inspect whether tables exist.

Check Startup Logs

Spring Boot startup logs often include schema actions. Look for:

HHH000262: Table not found …

or

Schema update complete

Production Best Practices

Use Explicit Schema Migration Tools

Auto schema creation is risky in production.

Use:

  • Flyway
  • Liquibase

These tools track schema changes safely and predictably.

Example Flyway config:

spring.flyway.enabled=true
spring.flyway.locations=classpath:db/migration

Avoid create or create-drop in Prod

These values are suitable for local development only.

In production, prefer:

  • validate (fail if mismatch)
  • External migration tools

Validate Entity Scanning Early

A missing table issue can often be traced to:

  • Incorrect package structure
  • Main class location
  • Custom configuration

Fixing these early avoids runtime errors.

Related Spring Boot Articles

Frequently Asked Questions

Why won’t Hibernate create my tables in production?

This usually results from:

  • Invalid DDL setting
  • Profile misconfiguration
  • Missing database privileges
  • Entity scanning issues

Should I use update in production?

It works for minor changes, but it’s safer to use migration tools like Flyway or Liquibase.

How can I verify which tables Hibernate created?

Enable SQL logging, then inspect the database using your client tools.

Summary

Spring Boot may not automatically create tables for several reasons — from wrong configuration to missing privileges.

You should:
✔ Check DDL settings
✔ Verify entity scanning
✔ Use profiles correctly
✔ Consider schema migration tools
✔ Inspect SQL logs

Applying these fixes will ensure your JPA entities are reflected as database tables reliably — both in development and production.

Leave a Comment

Your email address will not be published. Required fields are marked *