DATACMNS-1322 - Added @Immutable to allow users to express a persistent entity to be considered immutable.
This is needed for downstream projects that attempt to merge persistent entity instances and previously didn't have a chance to detect that an object had to be set as-is instead of being merged recursively.
This commit is contained in:
@@ -41,6 +41,7 @@ import org.springframework.data.annotation.AccessType;
|
||||
import org.springframework.data.annotation.AccessType.Type;
|
||||
import org.springframework.data.annotation.CreatedBy;
|
||||
import org.springframework.data.annotation.CreatedDate;
|
||||
import org.springframework.data.annotation.Immutable;
|
||||
import org.springframework.data.annotation.LastModifiedBy;
|
||||
import org.springframework.data.annotation.Persistent;
|
||||
import org.springframework.data.annotation.TypeAlias;
|
||||
@@ -347,6 +348,13 @@ public class BasicPersistentEntityUnitTests<T extends PersistentProperty<T>> {
|
||||
assertThat(entity.getIdentifierAccessor(new PersistableEntity()).getRequiredIdentifier()).isEqualTo(4711L);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1322
|
||||
public void detectsImmutableEntity() {
|
||||
|
||||
assertThat(createEntity(SomeValue.class).isImmutable()).isTrue();
|
||||
assertThat(createEntity(Entity.class).isImmutable()).isFalse();
|
||||
}
|
||||
|
||||
private <S> BasicPersistentEntity<S, T> createEntity(Class<S> type) {
|
||||
return createEntity(type, null);
|
||||
}
|
||||
@@ -416,4 +424,7 @@ public class BasicPersistentEntityUnitTests<T extends PersistentProperty<T>> {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Immutable
|
||||
static class SomeValue {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user