Skip to content

Commit 1f77786

Browse files
christophstroblmp911de
authored andcommitted
Don't create PersistentEntity for Nullable wrapper type.
Original pull request: #2394. Closes #2390.
1 parent 26c2db2 commit 1f77786

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

src/main/java/org/springframework/data/mapping/context/AbstractMappingContext.java

+18-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.util.concurrent.locks.ReentrantReadWriteLock;
3131
import java.util.function.Predicate;
3232
import java.util.stream.Collectors;
33+
import java.util.stream.StreamSupport;
3334

3435
import org.slf4j.Logger;
3536
import org.slf4j.LoggerFactory;
@@ -61,6 +62,7 @@
6162
import org.springframework.data.spel.ExtensionAwareEvaluationContextProvider;
6263
import org.springframework.data.util.ClassTypeInformation;
6364
import org.springframework.data.util.KotlinReflectionUtils;
65+
import org.springframework.data.util.NullableWrapperConverters;
6466
import org.springframework.data.util.Optionals;
6567
import org.springframework.data.util.Streamable;
6668
import org.springframework.data.util.TypeInformation;
@@ -483,6 +485,9 @@ protected boolean shouldCreatePersistentEntityFor(TypeInformation<?> type) {
483485
if (simpleTypeHolder.isSimpleType(type.getType())) {
484486
return false;
485487
}
488+
if(NullableWrapperConverters.supports(type.getType())) {
489+
return false;
490+
}
486491

487492
return !KotlinDetector.isKotlinType(type.getType()) || KotlinReflectionUtils.isSupportedKotlinClass(type.getType());
488493
}
@@ -569,7 +574,19 @@ private void createAndRegisterProperty(Property input) {
569574
return;
570575
}
571576

572-
property.getPersistentEntityTypes().forEach(AbstractMappingContext.this::addPersistentEntity);
577+
StreamSupport.stream(property.getPersistentEntityTypes().spliterator(), false)
578+
.map(it -> {
579+
if(it.isNullableWrapper()) {
580+
return it.getActualType();
581+
}
582+
return it;
583+
})
584+
.filter(it -> {
585+
586+
boolean shouldCreate = AbstractMappingContext.this.shouldCreatePersistentEntityFor(it);
587+
return shouldCreate;
588+
})
589+
.forEach(AbstractMappingContext.this::addPersistentEntity);
573590
}
574591

575592
protected boolean shouldSkipOverrideProperty(P property) {

src/main/java/org/springframework/data/util/TypeDiscoverer.java

+8
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,10 @@ public TypeInformation<?> getActualType() {
309309
return getComponentType();
310310
}
311311

312+
if (isNullableWrapper()) {
313+
return getComponentType();
314+
}
315+
312316
return this;
313317
}
314318

@@ -384,6 +388,10 @@ protected TypeInformation<?> doGetComponentType() {
384388
return getTypeArgument(Iterable.class, 0);
385389
}
386390

391+
if(isNullableWrapper()) {
392+
return getTypeArgument(rawType, 0);
393+
}
394+
387395
List<TypeInformation<?>> arguments = getTypeArguments();
388396

389397
return arguments.size() > 0 ? arguments.get(0) : null;

src/main/java/org/springframework/data/util/TypeInformation.java

+5
Original file line numberDiff line numberDiff line change
@@ -273,4 +273,9 @@ default TypeInformation<?> getRequiredSuperTypeInformation(Class<?> superType) {
273273
default boolean isSubTypeOf(Class<?> type) {
274274
return !type.equals(getType()) && type.isAssignableFrom(getType());
275275
}
276+
277+
default boolean isNullableWrapper() {
278+
return NullableWrapperConverters.supports(getType());
279+
}
280+
276281
}

0 commit comments

Comments
 (0)