Browse Source

Remove misleading `@Nullable` annotation from `AggregateReference.getId()`.

Aggregate references must be valid on their own and a null reference would represent a broken reference as we consider null identifiers as transient.

Closes #2104
3.5.x
Mark Paluch 4 months ago
parent
commit
f860f70545
No known key found for this signature in database
GPG Key ID: 55BC6374BAA9D973
  1. 13
      spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/mapping/AggregateReference.java

13
spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/mapping/AggregateReference.java

@ -31,14 +31,21 @@ import org.springframework.util.Assert;
*/ */
public interface AggregateReference<T, ID> { public interface AggregateReference<T, ID> {
/**
* Creates an {@link AggregateReference} that refers to the target aggregate root with the given id.
*
* @param id aggregate identifier. Must not be {@literal null}, can be a simple value.
* @return
* @param <T> target aggregate type.
* @param <ID> target aggregate identifier type.
*/
static <T, ID> AggregateReference<T, ID> to(ID id) { static <T, ID> AggregateReference<T, ID> to(ID id) {
return new IdOnlyAggregateReference<>(id); return new IdOnlyAggregateReference<>(id);
} }
/** /**
* @return the id of the referenced aggregate. May be {@code null}. * @return the id of the referenced aggregate.
*/ */
@Nullable
ID getId(); ID getId();
/** /**
@ -55,7 +62,6 @@ public interface AggregateReference<T, ID> {
public IdOnlyAggregateReference(ID id) { public IdOnlyAggregateReference(ID id) {
Assert.notNull(id, "Id must not be null"); Assert.notNull(id, "Id must not be null");
this.id = id; this.id = id;
} }
@ -82,7 +88,6 @@ public interface AggregateReference<T, ID> {
@Override @Override
public String toString() { public String toString() {
return "IdOnlyAggregateReference{" + "id=" + id + '}'; return "IdOnlyAggregateReference{" + "id=" + id + '}';
} }
} }

Loading…
Cancel
Save