Example of the use of @NamedQuery
In this example, a database ("example_mysql") is created based on Msql
The fundamental classes are
- Student
- StudentInterface
- DataLoader
- StudentController
The Student class is in charge of representing the model
The StudentInterface is in charge of create the JPA repository
The DataLoader class is in charge of populating the BD
TheStudentController class is in charge of bring the rest endpoints
Three named queries are defined in the model class
- @NamedQuery(name = "Student.findByEmailAddress", query = "select u from Student u where u.email = :email")
- @NamedQuery(name = "Student.findByName", query = "select u from Student u where u.name = :name")
- @NamedQuery(name = "Student.findAll", query = "SELECT u FROM Student u")
These named query are used in the controller class (StudentController)