Skip to content

Commit d1a3f10

Browse files
schaudermp911de
authored andcommitted
Adds a new snippet for is-new-state-detection.
This is intended for inclusion by other modules. Closes #2352.
1 parent 37b64f5 commit d1a3f10

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
[[is-new-state-detection]]
2+
= Entity State Detection Strategies
3+
4+
The following table describes the strategies that Spring Data offers for detecting whether an entity is new:
5+
6+
.Options for detection whether an entity is new in Spring Data
7+
[options = "autowidth",cols="1,1"]
8+
|===
9+
|Id-Property inspection (the default)
10+
|By default, Spring Data inspects the version property of the given entity.
11+
If the identifier property is `null` or `0` in case of primitive types, then the entity is assumed to be new.
12+
Otherwise, it is assumed to not be new.
13+
14+
|Version-Property inspection
15+
|If a property annotated with `@Version` is present and `null`, or in case of a version property of primitive type `0` the entity is considered new.
16+
If the version property is present but has a different value, the entity is considered to not be new.
17+
If no version property is present Spring Data falls back to inspection of the Id-Property.
18+
19+
|Implementing `Persistable`
20+
|If an entity implements `Persistable`, Spring Data delegates the new detection to the `isNew(…)` method of the entity.
21+
See the link:https://docs.spring.io/spring-data/data-commons/docs/current/api/index.html?org/springframework/data/domain/Persistable.html[Javadoc] for details.
22+
23+
_Note: Properties of `Persistable` will get detected and persisted if you use `AccessType.PROPERTY`.
24+
To avoid that, use `@Transient`._
25+
26+
|Implementing `EntityInformation`
27+
|You can customize the `EntityInformation` abstraction used in the repository base implementation by creating a subclass of the module specific repository factory and overriding the `getEntityInformation(…)` method.
28+
You then have to register the custom implementation of module specific repository factory as a Spring bean.
29+
Note that this should rarely be necessary.
30+
|===

0 commit comments

Comments
 (0)