Entity State Detection Strategies
-
@Id-Property 检查(默认):如果实体的 ID 属性为 null 或 0(对于基本类型),则实体被认为是新的。
-
@Version-Property 检查:如果带有 @Version 注释的属性存在且为 null,或者对于基本类型的版本属性为 0,则实体被认为是新的。
-
实现 Persistable:如果实体实现了 Persistable,Spring Data 将委托新检测到实体的 isNew(…) 方法。
-
提供自定义 EntityInformation 实现:通过创建模块特定存储库工厂的子类并覆盖 getEntityInformation(…) 方法,可以自定义存储库基本实现中使用的 EntityInformation 抽象。
下表描述了 Spring Data 提供的策略,用于检测实体是否新创建:
The following table describes the strategies that Spring Data offers for detecting whether an entity is new:
|
By default, Spring Data inspects the identifier property of the given entity.
If the identifier property is |
|
If a property annotated with |
Implementing |
If an entity implements Note: Properties of |
Providing a custom |
You can customize the |