banan3'14
banan3'14

Reputation: 5024

why Spring Data JPA documentation describes query methods starting only with find?

Reference documentation of Spring Data JPA framework describes query methods by examples. The example of such a method is findByEmailAddressAndLastname. It starts with find. Then they list all supported keywords inside method names. I figured out that the named queries must start with find.

However, the following method works as designed, despite the fact it starts with exists

@Repository
public interface UserRepository extends CrudRepository<User, Integer> {
    boolean existsUserByEmail(String email);
}

It runs a command

select user0_.id as col_0_0_ from users user0_ where user0_.email=? limit ?

and checks whether a user exists. But creating the method, I relied on IDE, rather than a documentation. Is there a statement anywhere either in Spring Data JPA docs or somewhere else (maybe Query DSL reference), which could be used to create such methods?

Upvotes: 1

Views: 602

Answers (1)

mmbouraoui
mmbouraoui

Reputation: 33

From Spring in action 4th Edition, Not only "find" is supported,it states "As you can see, the verb is read, as opposed to find from the previous example. Spring Data allows for four verbs in the method name: get, read, find, and count. The get, read, and find verbs are synonymous" The Keyword EXISTS is also mentioned here https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#new-features.1-11-0 as a new feature.

Upvotes: 1

Related Questions