Don't create PersistentEntity for Nullable wrapper type.
Original pull request: #2394. Closes #2390.
This commit is contained in:
committed by
Mark Paluch
parent
b92c00c445
commit
fe338de043
@@ -29,6 +29,7 @@ import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.BeansException;
|
||||
@@ -57,6 +58,7 @@ import org.springframework.data.spel.EvaluationContextProvider;
|
||||
import org.springframework.data.spel.ExtensionAwareEvaluationContextProvider;
|
||||
import org.springframework.data.util.ClassTypeInformation;
|
||||
import org.springframework.data.util.KotlinReflectionUtils;
|
||||
import org.springframework.data.util.NullableWrapperConverters;
|
||||
import org.springframework.data.util.Optionals;
|
||||
import org.springframework.data.util.Streamable;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
@@ -482,6 +484,9 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
|
||||
if (simpleTypeHolder.isSimpleType(type.getType())) {
|
||||
return false;
|
||||
}
|
||||
if(NullableWrapperConverters.supports(type.getType())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return !KotlinDetector.isKotlinType(type.getType()) || KotlinReflectionUtils.isSupportedKotlinClass(type.getType());
|
||||
}
|
||||
@@ -565,7 +570,19 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
|
||||
return;
|
||||
}
|
||||
|
||||
property.getPersistentEntityTypes().forEach(AbstractMappingContext.this::addPersistentEntity);
|
||||
StreamSupport.stream(property.getPersistentEntityTypes().spliterator(), false)
|
||||
.map(it -> {
|
||||
if(it.isNullableWrapper()) {
|
||||
return it.getActualType();
|
||||
}
|
||||
return it;
|
||||
})
|
||||
.filter(it -> {
|
||||
|
||||
boolean shouldCreate = AbstractMappingContext.this.shouldCreatePersistentEntityFor(it);
|
||||
return shouldCreate;
|
||||
})
|
||||
.forEach(AbstractMappingContext.this::addPersistentEntity);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -309,6 +309,10 @@ class TypeDiscoverer<S> implements TypeInformation<S> {
|
||||
return getComponentType();
|
||||
}
|
||||
|
||||
if (isNullableWrapper()) {
|
||||
return getComponentType();
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -384,6 +388,10 @@ class TypeDiscoverer<S> implements TypeInformation<S> {
|
||||
return getTypeArgument(Iterable.class, 0);
|
||||
}
|
||||
|
||||
if(isNullableWrapper()) {
|
||||
return getTypeArgument(rawType, 0);
|
||||
}
|
||||
|
||||
List<TypeInformation<?>> arguments = getTypeArguments();
|
||||
|
||||
return arguments.size() > 0 ? arguments.get(0) : null;
|
||||
|
||||
@@ -273,4 +273,9 @@ public interface TypeInformation<S> {
|
||||
default boolean isSubTypeOf(Class<?> type) {
|
||||
return !type.equals(getType()) && type.isAssignableFrom(getType());
|
||||
}
|
||||
|
||||
default boolean isNullableWrapper() {
|
||||
return NullableWrapperConverters.supports(getType());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user