From 3319488c96671e54db40b73ffeeb8b37b74fa869 Mon Sep 17 00:00:00 2001 From: Johan Sogaard Date: Thu, 8 May 2025 19:49:19 +0200 Subject: [PATCH 1/2] Changed equals method in VariableId to fix VariableId not being found when using the two objects as hashkey --- .../listener/support/violation/VariableId.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/ai/timefold/solver/core/impl/domain/variable/listener/support/violation/VariableId.java b/core/src/main/java/ai/timefold/solver/core/impl/domain/variable/listener/support/violation/VariableId.java index 6817d81e10..b12995fcbb 100644 --- a/core/src/main/java/ai/timefold/solver/core/impl/domain/variable/listener/support/violation/VariableId.java +++ b/core/src/main/java/ai/timefold/solver/core/impl/domain/variable/listener/support/violation/VariableId.java @@ -6,7 +6,11 @@ * A {@link VariableId} is an entity/variable of a given solution. * {@link VariableId} cannot be compared across different solution instances, * since variableDescriptor and entity are compared by reference equality. - * + *

+ * Note: The entity is compared using {@link Object#equals(Object)} and {@link Object#hashCode()}, + * so it's important that the planning entity class properly overrides both methods, + * typically based on a unique identifier (e.g. a database ID or business key). + *

* @param variableDescriptor The variable this {@link VariableId} refers to. * @param entity The entity this {@link VariableId} refers to. */ @@ -14,8 +18,8 @@ public record VariableId(VariableDescriptor variableDescri @Override public boolean equals(Object other) { if (other instanceof VariableId variableId) { - return variableDescriptor == variableId.variableDescriptor && - entity == variableId.entity; + return variableDescriptor.equals(variableId.variableDescriptor) && + entity.equals(variableId.entity); } return false; } From 273d783a902f9f57d11bd18148a3b52aeb92fd27 Mon Sep 17 00:00:00 2001 From: Johan Sogaard Date: Thu, 8 May 2025 21:01:19 +0200 Subject: [PATCH 2/2] Changed equals method in VariableId to fix VariableId not being found when using the two objects as hashkey --- .../domain/variable/listener/support/violation/VariableId.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/ai/timefold/solver/core/impl/domain/variable/listener/support/violation/VariableId.java b/core/src/main/java/ai/timefold/solver/core/impl/domain/variable/listener/support/violation/VariableId.java index b12995fcbb..53d4832770 100644 --- a/core/src/main/java/ai/timefold/solver/core/impl/domain/variable/listener/support/violation/VariableId.java +++ b/core/src/main/java/ai/timefold/solver/core/impl/domain/variable/listener/support/violation/VariableId.java @@ -9,7 +9,7 @@ *

* Note: The entity is compared using {@link Object#equals(Object)} and {@link Object#hashCode()}, * so it's important that the planning entity class properly overrides both methods, - * typically based on a unique identifier (e.g. a database ID or business key). + * typically based on a unique identifier (e.g. a UId). *

* @param variableDescriptor The variable this {@link VariableId} refers to. * @param entity The entity this {@link VariableId} refers to.