You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/main/asciidoc/repositories.adoc
+23-6
Original file line number
Diff line number
Diff line change
@@ -210,17 +210,34 @@ The sections that follow explain each step in detail:
210
210
211
211
To define a repository interface, you first need to define a domain class-specific repository interface.
212
212
The interface must extend `Repository` and be typed to the domain class and an ID type.
213
-
If you want to expose CRUD methods for that domain type, extend `CrudRepository` instead of `Repository`.
213
+
If you want to expose CRUD methods for that domain type, you may extend `CrudRepository`, or one of its variants instead of `Repository`.
214
214
215
215
[[repositories.definition-tuning]]
216
216
=== Fine-tuning Repository Definition
217
217
218
-
Typically, your repository interface extends `Repository`, `CrudRepository`, or `PagingAndSortingRepository`.
219
-
Alternatively, if you do not want to extend Spring Data interfaces, you can also annotate your repository interface with `@RepositoryDefinition`.
220
-
Extending `CrudRepository` exposes a complete set of methods to manipulate your entities.
221
-
If you prefer to be selective about the methods being exposed, copy the methods you want to expose from `CrudRepository` into your domain repository.
218
+
There are a few variants how you can get started with your repository interface.
222
219
223
-
NOTE: Doing so lets you define your own abstractions on top of the provided Spring Data Repositories functionality.
220
+
The typical approach is to extend `CrudRepository`, which gives you methods for CRUD functionality.
221
+
CRUD stands for Create, Read, Update, Delete.
222
+
223
+
If you are using a reactive store you might choose `ReactiveCrudRepository`, or `RxJava3CrudRepository` depending on which reactive framework you are using.
224
+
225
+
If you are using Kotlin you might pick `CoroutineCrudRepository` which utilizes Kotlin's coroutines.
226
+
227
+
Alternatively you can extend `PagingAndSortingRepository`, `ReactiveSortingRepository`, `RxJava3SortingRepository`, or `CoroutineSortingRepository` if you need methods that allow to specify a `Sort` abstraction or in the first case a `Pageable` abstraction.
228
+
These interfaces currently extend the respective CRUD repository of the underlying technology, but will stop to do so with version 3.0.x.
229
+
Therefore, we considere it good practice to explicitly inherit from these CRUD repositories explicitely.
230
+
231
+
If you do not want to extend Spring Data interfaces, you can also annotate your repository interface with `@RepositoryDefinition`.
232
+
Extending one of the CRUD repository interfaces exposes a complete set of methods to manipulate your entities.
233
+
If you prefer to be selective about the methods being exposed, copy the methods you want to expose from the CRUD repository into your domain repository.
234
+
When doing so, you may change the return type of methods.
235
+
Spring Data will honor the return type if possible.
236
+
For example, for methods returning multiple entities you may choose `Iterable<T>`, `List<T>`, `Collection<T>` or a VAVR list.
237
+
238
+
If many repositories in your application should have the same set of methods you can define your own base interface to inherit from.
239
+
Such an interface must be annotated with `@NoRepositoryBean`.
240
+
This prevents Spring Data to try to create an instance of it directly and failing because it can't determine the entity for that repository, since it still contains a generic type variable.
224
241
225
242
The following example shows how to selectively expose CRUD methods (`findById` and `save`, in this case):
0 commit comments