diff --git a/src/main/java/org/springframework/data/mapping/model/AbstractPersistentProperty.java b/src/main/java/org/springframework/data/mapping/model/AbstractPersistentProperty.java index 87bb00e35..c4b7a1176 100644 --- a/src/main/java/org/springframework/data/mapping/model/AbstractPersistentProperty.java +++ b/src/main/java/org/springframework/data/mapping/model/AbstractPersistentProperty.java @@ -257,7 +257,7 @@ public abstract class AbstractPersistentProperty

TypeInformation actualType = information.getActualType(); boolean isComplexType = actualType == null ? false : !simpleTypeHolder.isSimpleType(actualType.getType()); - return isComplexType && !isTransient() && !isCollectionLike() && !isMap(); + return isComplexType && !isTransient(); } /* diff --git a/src/test/java/org/springframework/data/mapping/context/AbstractMappingContextUnitTests.java b/src/test/java/org/springframework/data/mapping/context/AbstractMappingContextUnitTests.java index a1fba1f11..5f464a456 100644 --- a/src/test/java/org/springframework/data/mapping/context/AbstractMappingContextUnitTests.java +++ b/src/test/java/org/springframework/data/mapping/context/AbstractMappingContextUnitTests.java @@ -224,6 +224,16 @@ public class AbstractMappingContextUnitTests { assertThat(context.getPersistentEntity(Integer.class), is(nullValue())); } + /** + * @see DATACMNS-462 + */ + @Test + public void hasPersistentEntityForCollectionPropertiesAfterInitialization() { + + context.getPersistentEntity(Sample.class); + assertThat(context.hasPersistentEntityFor(Person.class), is(true)); + } + class Person { String name; } diff --git a/src/test/java/org/springframework/data/mapping/model/AbstractPersistentPropertyUnitTests.java b/src/test/java/org/springframework/data/mapping/model/AbstractPersistentPropertyUnitTests.java index ebaf53d44..7723426aa 100644 --- a/src/test/java/org/springframework/data/mapping/model/AbstractPersistentPropertyUnitTests.java +++ b/src/test/java/org/springframework/data/mapping/model/AbstractPersistentPropertyUnitTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2011-2013 the original author or authors. + * Copyright 2011-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -51,6 +51,7 @@ public class AbstractPersistentPropertyUnitTests { @Before public void setUp() { + typeInfo = ClassTypeInformation.from(TestClassComplex.class); entity = new BasicPersistentEntity(typeInfo); typeHolder = new SimpleTypeHolder(); @@ -68,6 +69,9 @@ public class AbstractPersistentPropertyUnitTests { property.getComponentType(); } + /** + * @see DATACMNS-101 + */ @Test public void returnsNestedEntityTypeCorrectly() { @@ -197,25 +201,6 @@ public class AbstractPersistentPropertyUnitTests { assertThat(property.getSetter(), is(nullValue())); } - private static PropertyDescriptor getPropertyDescriptor(Class type, String propertyName) { - - try { - - BeanInfo info = Introspector.getBeanInfo(type); - - for (PropertyDescriptor descriptor : info.getPropertyDescriptors()) { - if (descriptor.getName().equals(propertyName)) { - return descriptor; - } - } - - return null; - - } catch (IntrospectionException e) { - return null; - } - } - /** * @see DATACMNS-337 */ @@ -235,6 +220,46 @@ public class AbstractPersistentPropertyUnitTests { assertThat(property.getActualType(), is((Object) Person.class)); } + /** + * @see DATACMNS-462 + */ + @Test + public void considersCollectionPropertyEntitiesIfComponentTypeIsEntity() { + + SamplePersistentProperty property = getProperty(Sample.class, "persons"); + assertThat(property.isEntity(), is(true)); + } + + /** + * @see DATACMNS-462 + */ + @Test + public void considersMapPropertyEntitiesIfValueTypeIsEntity() { + + SamplePersistentProperty property = getProperty(Sample.class, "personMap"); + assertThat(property.isEntity(), is(true)); + } + + /** + * @see DATACMNS-462 + */ + @Test + public void considersArrayPropertyEntitiesIfComponentTypeIsEntity() { + + SamplePersistentProperty property = getProperty(Sample.class, "personArray"); + assertThat(property.isEntity(), is(true)); + } + + /** + * @see DATACMNS-462 + */ + @Test + public void considersCollectionPropertySimpleIfComponentTypeIsSimple() { + + SamplePersistentProperty property = getProperty(Sample.class, "strings"); + assertThat(property.isEntity(), is(false)); + } + private SamplePersistentProperty getProperty(Class type, String name) { BasicPersistentEntity entity = new BasicPersistentEntity( @@ -244,6 +269,25 @@ public class AbstractPersistentPropertyUnitTests { return new SamplePersistentProperty(field, null, entity, typeHolder); } + private static PropertyDescriptor getPropertyDescriptor(Class type, String propertyName) { + + try { + + BeanInfo info = Introspector.getBeanInfo(type); + + for (PropertyDescriptor descriptor : info.getPropertyDescriptors()) { + if (descriptor.getName().equals(propertyName)) { + return descriptor; + } + } + + return null; + + } catch (IntrospectionException e) { + return null; + } + } + class Generic { T genericField; @@ -345,5 +389,6 @@ public class AbstractPersistentPropertyUnitTests { Collection persons; Person[] personArray; Map personMap; + Collection strings; } }