Basic Tutorial
Queries
@NamedQuery allows defining reusable JPQL queries inside the entity class.
Let's assume we have a User entity with fields: id, name, email and age.
Table name : user
| id | name | age | |
|---|---|---|---|
| 1 | John | john@gmail.com | 25 |
| 2 | Mike | mike@gmail.com | 35 |
| 3 | Watson | watson@gmail.com | 40 |
| 4 | Kenny | kenny@gmail.com | 45 |
Once the application is running, test the endpoints:
GET:http://localhost:8080/users
GET:http://localhost:8080/users/{userName}
GET:http://localhost:8080/users/older/{age}
@NamedNativeQuery)If you need raw SQL, use @NamedNativeQuery instead of @NamedQuery.