Named Query

is to use named queries defined on the entity itself. The following example shows how to define a named query on

    @Entity
@NamedQuery(name = "User.findUsersWithNameUsingNamedQuery",
query = "select u from User u where u.name = ?1")
public class User {

To use this query in a repository, we would need to create a method with the same name as the named query. The following snippet shows the corresponding method in UserRepository:

    List<User> findUsersWithNameUsingNamedQuery(String name);

Note that the name of the named query is User.findUsersWithNameUsingNamedQuery. So, the name of the method in the repository should be findUsersWithNameUsingNamedQuery.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset