๐ด The Error You're Seeing
Confirm this matches your console output. If it does, you're in the right place.
2026-03-01 19:15:20.000 ERROR 8842 --- [ main] o.s.boot.SpringApplication : Application run failed
org.hibernate.hql.internal.ast.QuerySyntaxException: Unexpected token: FROM [FROM User u WHERE u.active = true]โก Quick Fix Works 80% of the time
Add the SELECT clause to your JPQL query.
@Query("SELECT u FROM User u WHERE u.active = true")
List<User> findActiveUsers();๐ง Why this Happens
Tap to expand the deep technical explanation
Hibernate's JPQL parser read your query string and found a grammatical error. In JPQL, you cannot omit the 'SELECT' clause (unlike some SQL dialects), and using SQL keywords incorrectly will trigger this exception.
The HITEC City Parking Spot Analogy:
It is like writing a sentence without a subject. 'Went to the store' makes sense in casual speech, but a strict grammar parser (Hibernate) rejects it because it lacks 'I' (the SELECT).
๐ How to Reproduce Confirm this is your error
Write a JPQL query that starts with FROM and has no SELECT clause (for example 'FROM User u'), then call the repository method. Hibernate throws QuerySyntaxException: Unexpected token: FROM.
๐ ๏ธ Solutions (3 Ways to Fix)
Add the SELECT clause
๐ Use this if you wrote 'FROM User' instead of 'SELECT u FROM User'.
Unlike SQL, JPQL strictly requires the SELECT clause. 'FROM User' is invalid; it must be 'SELECT u FROM User u'.
// Bad
@Query("FROM User u")
// Good
@Query("SELECT u FROM User u")Check for typos in Entity names
๐ Use this if your SELECT is present but the error persists.
JPQL uses Java class names, not table names. Ensure 'User' matches the exact class name, not the table name 'users'.
// Entity: @Entity public class UserEntity
// Bad: SELECT u FROM User u
// Good: SELECT u FROM UserEntity uValidate named queries at startup
๐ Use this to catch syntax errors before runtime.
If you use @NamedQuery, Hibernate validates them at startup. For @Query, ensure you don't have native SQL syntax mixed with JPQL.
@Entity
@NamedQueries({
@NamedQuery(name = "User.findActive", query = "SELECT u FROM User u WHERE u.active = true")
})
public class User { ... }๐ Version Notes
Uses Hibernate 5 HQL parser.
Uses Hibernate 6 HQL parser, slightly different error messages.
๐ก๏ธ How to Prevent This Next Time
Always use 'SELECT alias FROM Entity alias'. Use Spring Data JPA derived queries (findByActiveTrue) to avoid writing JPQL entirely.