> For the complete documentation index, see [llms.txt](https://bernardo.gitbook.io/development-docs-java/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://bernardo.gitbook.io/development-docs-java/spring-data/jpa-repositories/queries.md).

# Queries

## Query Methods

Any implementation of Spring's Repository can define custom queries through method names.

For example, this will fetch all the entity with a specific name:

```java
public interface EntityRepository extends JpaRepository<Entity, EntityKey> {

   public Iterable<Entity> findByName(final String name);

}
```

## JPQL

It is possible to define the query which a method will use:

```java
@Query("SELECT e FROM Entity e WHERE e.name = :name")
public Iterable<Entity> findByNameJpql(@Param("name") final String name);
```

Notice that it is using a named argument.

### SpEL in Queries <a href="#jpa.query.spel-expressions" id="jpa.query.spel-expressions"></a>

To find out automatically the received entity name (useful when extending the entity):

```java
@Query("SELECT e FROM #{#entityName} e WHERE e.name = :name")
public Iterable<Entity> findByNameJpql(@Param("name") final String name);
```

## Query by Example

```java
Example<Employee> example;
Iterable<Employee> employees;

example = Example.of(emp);

employees = repository.findAll(example);
```

## More Information

* [Query Methods](https://docs.spring.io/spring-data/jpa/docs/2.2.0.RELEASE/reference/html/#repositories.query-methods)
