๐Ÿ”ด The Error You're Seeing

Confirm this matches your console output. If it does, you're in the right place.

ERROR LOG2023-10-25 10:15:30.812 ERROR 12345 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute statement; SQL [n/a]] with root cause org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "USER" not found; SQL statement: insert into user (email, name, id) values (?, ?, ?) [42102-214]

โšก Quick Fix Works 80% of the time

Set spring.jpa.hibernate.ddl-auto=update to let Hibernate create the tables automatically.

# application.properties spring.jpa.hibernate.ddl-auto=update

๐Ÿ› ๏ธ Solutions (3 Ways to Fix)

Solution 1โœ“ Most common cause

Enable Hibernate auto-schema generation

๐Ÿ‘‰ Use this during development when your Entity classes exist but the database tables haven't been created.

Setting ddl-auto to 'update' tells Hibernate to scan your @Entity classes and automatically create or alter the database tables to match.

# application.properties spring.jpa.hibernate.ddl-auto=update
Solution 2

Fix @Table name mismatch

๐Ÿ‘‰ Use this if your table exists in the DB but your Entity is looking for the wrong name.

Hibernate defaults to the class name for the table name. If your DB table is 'users' but your class is 'User', it will fail. Use @Table to map them explicitly.

@Entity @Table(name = "users") public class User { ... }
Solution 3

Initialize database with data.sql

๐Ÿ‘‰ Use this if you have a custom schema.sql file that isn't running.

Ensure your schema.sql file is in src/main/resources and that Spring Boot is configured to run it.

# application.properties spring.sql.init.mode=always spring.jpa.defer-datasource-initialization=true

๐Ÿ“‹ Version Notes

Spring Boot 2.x

spring.sql.init.mode defaults to embedded. schema.sql runs automatically for H2.

Spring Boot 3.x

spring.sql.init.mode defaults to embedded, but defer-datasource-initialization is needed if using Hibernate ddl-auto with schema.sql.

๐Ÿง  Why this Happens

Tap to expand the deep technical explanation

Hibernate generated a SQL query (like SELECT or INSERT) for an Entity, but when it sent that query to the database, the database responded that the table doesn't exist. This usually means your Entity classes haven't been mapped to actual database tables yet.

The HITEC City Parking Spot Analogy:

It's like trying to put a letter in a mailbox, but the mailbox hasn't been built yet. You have the letter (data), but nowhere to put it.

๐Ÿ›ก๏ธ How to Prevent This Next Time

Always set spring.jpa.hibernate.ddl-auto=update during development, or use Flyway/Liquibase for production schema management.

Course Search
Search across all chapters & stages
๐Ÿ“–

Search the course

Type any topic โ€” branching, stash, rebase, hooks โ€” and jump straight to that chapter.

merge branchesgit stashundo commitrebase