From f860f70545a5c5675cfaa9676c60080cdb19fc5a Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Mon, 11 Aug 2025 15:59:27 +0200 Subject: [PATCH] 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 --- .../data/jdbc/core/mapping/AggregateReference.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/mapping/AggregateReference.java b/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/mapping/AggregateReference.java index a75054588..08ab0b324 100644 --- a/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/mapping/AggregateReference.java +++ b/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 { + /** + * 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 target aggregate type. + * @param target aggregate identifier type. + */ static AggregateReference to(ID 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(); /** @@ -55,7 +62,6 @@ public interface AggregateReference { public IdOnlyAggregateReference(ID id) { Assert.notNull(id, "Id must not be null"); - this.id = id; } @@ -82,7 +88,6 @@ public interface AggregateReference { @Override public String toString() { - return "IdOnlyAggregateReference{" + "id=" + id + '}'; } }