๐Ÿ”ด The Error You're Seeing

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

ERROR LOG2026-02-14 13:40:05.500 ERROR 8842 --- [nio-8080-exec-5] 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 java.sql.SQLSyntaxErrorException: Unknown column 'user_name' in 'field list'

โšก Quick Fix Works 80% of the time

Ensure your @Column(name = "...") annotation exactly matches the column name in your database table.

@Entity public class User { @Column(name = "username") // Match the DB exactly private String userName; }

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

Solution 1โœ“ Most common cause

Fix the @Column name mapping

๐Ÿ‘‰ Use this when your Java variable name differs from your database column name.

Hibernate uses snake_case by default to map camelCase Java fields. If your DB column is 'username' but Java has 'userName', Hibernate looks for 'user_name'. Explicitly map it.

@Entity public class User { @Column(name = "username") private String userName; }
Solution 2

Update the database schema

๐Ÿ‘‰ Use this if your Java code is correct, but the database table is out of date.

If you recently added a field to your Entity, the database table might not have that column yet. Let Hibernate update it.

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

Use a custom JPQL/Native query

๐Ÿ‘‰ Use this if you are writing a manual @Query and misspelled the column name.

In JPQL, you use Java field names (u.userName). In Native SQL, you use DB column names (user_name). Ensure you aren't mixing them up.

// JPQL (uses Java fields) @Query("SELECT u FROM User u WHERE u.userName = :name") // Native SQL (uses DB columns) @Query(value = "SELECT * FROM users WHERE username = :name", nativeQuery = true)

๐Ÿ“‹ Version Notes

Spring Boot 2.x

Uses Hibernate 5. SpringPhysicalNamingStrategy maps camelCase to snake_case.

Spring Boot 3.x

Uses Hibernate 6. CamelCaseToSnakeCaseNamingStrategy is default, but stricter on explicit @Column names.

๐Ÿง  Why this Happens

Tap to expand the deep technical explanation

Hibernate generated an SQL INSERT or SELECT statement based on your Java Entity class. When it sent that query to the database, the database responded that it doesn't have a column with the exact name Hibernate requested.

The HITEC City Parking Spot Analogy:

It is like asking a librarian for a book titled 'The Lord of the Rings', but the library only has it cataloged under 'LOTR'. The librarian (database) cannot find the book because the name doesn't match.

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

Use spring.jpa.hibernate.ddl-auto=update during development so Hibernate creates the columns exactly as it expects them.

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