Fix KotlinCopyMethod detection for single-association property classes.

KotlinCopyMethod.shouldUsePublicCopyMethod(…) now considers single-association arrangements. Also, the method now early exists if pre-conditions aren't met.

Closes #3131
This commit is contained in:
Mark Paluch
2024-08-06 15:14:18 +02:00
parent 6e1e5226f4
commit 09258ccc60
3 changed files with 40 additions and 1 deletions

View File

@@ -38,6 +38,7 @@ import java.util.stream.Collectors;
import org.springframework.core.ResolvableType;
import org.springframework.data.mapping.PersistentEntity;
import org.springframework.data.mapping.PersistentProperty;
import org.springframework.data.mapping.SimpleAssociationHandler;
import org.springframework.data.mapping.SimplePropertyHandler;
import org.springframework.data.util.KotlinReflectionUtils;
import org.springframework.util.Assert;
@@ -158,8 +159,9 @@ class KotlinCopyMethod {
List<PersistentProperty<?>> persistentProperties = new ArrayList<>();
entity.doWithProperties((SimplePropertyHandler) persistentProperties::add);
entity.doWithAssociations((SimpleAssociationHandler) it -> persistentProperties.add(it.getInverse()));
if (persistentProperties.size() > 1) {
if (persistentProperties.size() != 1) {
return false;
}