๐ด The Error You're Seeing
Confirm this matches your console output. If it does, you're in the right place.
2026-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)
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;
}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=updateUse 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
Uses Hibernate 5. SpringPhysicalNamingStrategy maps camelCase to snake_case.
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.