Skip to content

Commit 0731b72

Browse files
committed
DATACMNS-1444 - Polishing.
Removed references to Serializable in repository interface declarations. Reformatting to waste less space with lines only containing ellipsis.
1 parent defbff4 commit 0731b72

File tree

1 file changed

+18
-44
lines changed

1 file changed

+18
-44
lines changed

src/main/asciidoc/repositories.adoc

Lines changed: 18 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ The central interface in the Spring Data repository abstraction is `Repository`.
2222
====
2323
[source, java]
2424
----
25-
public interface CrudRepository<T, ID extends Serializable>
26-
extends Repository<T, ID> {
25+
public interface CrudRepository<T, ID> extends Repository<T, ID> {
2726
2827
<S extends T> S save(S entity); <1>
2928
@@ -56,8 +55,7 @@ On top of the `CrudRepository`, there is a `PagingAndSortingRepository` abstract
5655
====
5756
[source, java]
5857
----
59-
public interface PagingAndSortingRepository<T, ID extends Serializable>
60-
extends CrudRepository<T, ID> {
58+
public interface PagingAndSortingRepository<T, ID> extends CrudRepository<T, ID> {
6159
6260
Iterable<T> findAll(Sort sort);
6361
@@ -135,7 +133,7 @@ interface PersonRepository extends Repository<Person, Long> {
135133
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
136134
137135
@EnableJpaRepositories
138-
class Config {}
136+
class Config {}
139137
----
140138

141139

@@ -208,7 +206,7 @@ The following example shows how to selectively expose CRUD methods (`findById` a
208206
[source, java]
209207
----
210208
@NoRepositoryBean
211-
interface MyBaseRepository<T, ID extends Serializable> extends Repository<T, ID> {
209+
interface MyBaseRepository<T, ID> extends Repository<T, ID> {
212210
213211
Optional<T> findById(ID id);
214212
@@ -243,13 +241,9 @@ The following example shows a repository that uses module-specific interfaces (J
243241
interface MyRepository extends JpaRepository<User, Long> { }
244242
245243
@NoRepositoryBean
246-
interface MyBaseRepository<T, ID extends Serializable> extends JpaRepository<T, ID> {
247-
248-
}
244+
interface MyBaseRepository<T, ID> extends JpaRepository<T, ID> { … }
249245
250-
interface UserRepository extends MyBaseRepository<User, Long> {
251-
252-
}
246+
interface UserRepository extends MyBaseRepository<User, Long> { … }
253247
----
254248
`MyRepository` and `UserRepository` extend `JpaRepository` in their type hierarchy. They are valid candidates for the Spring Data JPA module.
255249
====
@@ -260,18 +254,12 @@ The following example shows a repository that uses generic interfaces:
260254
====
261255
[source, java]
262256
----
263-
interface AmbiguousRepository extends Repository<User, Long> {
264-
265-
}
257+
interface AmbiguousRepository extends Repository<User, Long> { … }
266258
267259
@NoRepositoryBean
268-
interface MyBaseRepository<T, ID extends Serializable> extends CrudRepository<T, ID> {
269-
270-
}
260+
interface MyBaseRepository<T, ID> extends CrudRepository<T, ID> { … }
271261
272-
interface AmbiguousUserRepository extends MyBaseRepository<User, Long> {
273-
274-
}
262+
interface AmbiguousUserRepository extends MyBaseRepository<User, Long> { … }
275263
----
276264
`AmbiguousRepository` and `AmbiguousUserRepository` extend only `Repository` and `CrudRepository` in their type hierarchy. While this is perfectly fine when using a unique Spring Data module, multiple modules cannot distinguish to which particular Spring Data these repositories should be bound.
277265
====
@@ -283,23 +271,15 @@ The following example shows a repository that uses domain classes with annotatio
283271
====
284272
[source, java]
285273
----
286-
interface PersonRepository extends Repository<Person, Long> {
287-
288-
}
274+
interface PersonRepository extends Repository<Person, Long> { … }
289275
290276
@Entity
291-
class Person {
292-
293-
}
277+
class Person { … }
294278
295-
interface UserRepository extends Repository<User, Long> {
296-
297-
}
279+
interface UserRepository extends Repository<User, Long> { … }
298280
299281
@Document
300-
class User {
301-
302-
}
282+
class User { … }
303283
----
304284
`PersonRepository` references `Person`, which is annotated with the JPA `@Entity` annotation, so this repository clearly belongs to Spring Data JPA. `UserRepository` references `User`, which is annotated with Spring Data MongoDB's `@Document` annotation.
305285
====
@@ -310,19 +290,13 @@ The following bad example shows a repository that uses domain classes with mixed
310290
====
311291
[source, java]
312292
----
313-
interface JpaPersonRepository extends Repository<Person, Long> {
314-
315-
}
293+
interface JpaPersonRepository extends Repository<Person, Long> { … }
316294
317-
interface MongoDBPersonRepository extends Repository<Person, Long> {
318-
319-
}
295+
interface MongoDBPersonRepository extends Repository<Person, Long> { … }
320296
321297
@Entity
322298
@Document
323-
class Person {
324-
325-
}
299+
class Person { … }
326300
----
327301
This example shows a domain class using both JPA and Spring Data MongoDB annotations. It defines two repositories, `JpaPersonRepository` and `MongoDBPersonRepository`. One is intended for JPA and the other for MongoDB usage. Spring Data is no longer able to tell the repositories apart, which leads to undefined behavior.
328302
====
@@ -339,7 +313,7 @@ The following example shows annotation-driven configuration of base packages:
339313
----
340314
@EnableJpaRepositories(basePackages = "com.acme.repositories.jpa")
341315
@EnableMongoRepositories(basePackages = "com.acme.repositories.mongo")
342-
interface Configuration { }
316+
class Configuration { }
343317
----
344318
====
345319

@@ -1002,7 +976,7 @@ The approach described in the <<repositories.manual-wiring,preceding section>> r
1002976
====
1003977
[source, java]
1004978
----
1005-
class MyRepositoryImpl<T, ID extends Serializable>
979+
class MyRepositoryImpl<T, ID>
1006980
extends SimpleJpaRepository<T, ID> {
1007981
1008982
private final EntityManager entityManager;

0 commit comments

Comments
 (0)