Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
<version>3.4.0-SNAPSHOT</version>
<version>3.4.0-3173-SNAPSHOT</version>

<name>Spring Data Core</name>
<description>Core Spring concepts underpinning every Spring Data module.</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ public interface CrudRepository<T, ID> extends Repository<T, ID> {
The methods declared in this interface are commonly referred to as CRUD methods.
`ListCrudRepository` offers equivalent methods, but they return `List` where the `CrudRepository` methods return an `Iterable`.

[IMPORTANT]
====
The repository interface implies a few reserved methods like `findById(ID identifier)` that always target the domain types identifier property regardless of its property name. Read more about this in "`xref:repositories/query-methods-details.adoc#repositories.query-methods.reserved-methods[Defining Query Methods]`".
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to watch for broken references in case a Data module doesn't ship a repositories/query-methods-details.adoc documentation page.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there one you're aware of right off the top of your head?

====

NOTE: We also provide persistence technology-specific abstractions, such as `JpaRepository` or `MongoRepository`.
Those interfaces extend `CrudRepository` and expose the capabilities of the underlying persistence technology in addition to the rather generic persistence technology-agnostic interfaces such as `CrudRepository`.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,20 @@ Consult the store-specific documentation for the exact list of supported keyword
|`…Distinct…`| Use a distinct query to return only unique results. Consult the store-specific documentation whether that feature is supported. This keyword can occur in any place of the subject between `find` (and the other keywords) and `by`.
|===============

[[appendix.query.method.reserved]]
== Reserved methods

The following table lists reserved methods that use predefined functionality which is directly invoked on the backing (store specific) implementation of the repository proxy. See also "`xref:repositories/query-methods-details.adoc#repositories.query-methods.reserved-methods[Defining Query Methods]`".

.Reserved methods
|===============
|`deleteAllById(Iterable<ID> identifiers)`
|`deleteById(ID identifier)`
|`existsById(ID identifier)`
|`findAllById(Iterable<ID> identifiers)`
|`findById(ID identifier)`
|===============

[[appendix.query.method.predicate]]
== Supported query method predicate keywords and modifiers

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,37 @@ Whether ignoring cases is supported may vary by store, so consult the relevant s
- You can apply static ordering by appending an `OrderBy` clause to the query method that references a property and by providing a sorting direction (`Asc` or `Desc`).
To create a query method that supports dynamic sorting, see "`xref:repositories/query-methods-details.adoc#repositories.special-parameters[Paging, Iterating Large Results, Sorting & Limiting]`".

[[repositories.query-methods.reserved-methods]]
== Reserved Methods

While repository methods typically bind to properties by name, there are a few exceptions to this rule when it comes to certain method names targeting the _identifier_ property. Those _reserved methods_ like `CrudRepository#findById` or just `findById` are targeting the _identifier_ property independent of the actual property name used in the declared method. +
Consider the following domain type holding a property `pk` marked as the identifier via `@Id` and a property called `id`. In this case you need to pay close attention to the naming of your lookup methods as they may collide with predefined signatures.

====
[source,java]
----
public class User {
@Id
Long pk; <1>
Long id; <2>
// ...
}

public interface UserRepository extends Repository<User, Long> {
Optional<User> findById(Long id); <3>
Optional<User> findByPk(Long pk); <4>
Optional<User> findUserById(Long id); <5>
}
----
<1> The identifier property / primary key.
<2> A property called id, but not the identifying one.
<3> Targets the `User#pk` property (the one marked with `@Id` which is considered to be the identifier) instead of `User#id` as the property name would suggest because it is one of the _reserved methods_.
<4> Targets the `User#pk` property by name.
<5> Targets the `User#id` property by using the descriptive token between `find` and `by` to avoid collisions with _reserved methods_.
====

This special behaviour not only targets lookup methods but also applies to the `exits` and `delete` ones. Please refer to the "`xref:repositories/query-keywords-reference.adoc#appendix.query.method.reserved[Repository query keywords]`" for the list of methods.

[[repositories.query-methods.query-property-expressions]]
== Property Expressions

Expand Down