Skip to content

Commit 2afb570

Browse files
Thomas Darimontodrotbohm
Thomas Darimont
authored andcommitted
DATACMNS-345 - Use the actual type of the persistent property.
Changed getPersistentEntity(PersistentProperty<?>) to return the actual type of the persistent property in order to deal with collection and map types transparently. Original pull request: #31.
1 parent 634789c commit 2afb570

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,8 @@ public E getPersistentEntity(P persistentProperty) {
178178
return null;
179179
}
180180

181-
try {
182-
read.lock();
183-
return persistentEntities.get(persistentProperty.getTypeInformation());
184-
} finally {
185-
read.unlock();
186-
}
181+
TypeInformation<?> typeInfo = persistentProperty.getTypeInformation();
182+
return getPersistentEntity(typeInfo.getActualType());
187183
}
188184

189185
/*

src/test/java/org/springframework/data/mapping/context/AbstractMappingContextUnitTests.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import groovy.lang.MetaClass;
2222

2323
import java.util.Collections;
24+
import java.util.List;
2425

2526
import org.junit.Before;
2627
import org.junit.Test;
@@ -144,7 +145,7 @@ public void doesNotCreatePersistentPropertyForGroovyMetaClass() {
144145
}
145146

146147
/**
147-
* @see DATACMNS-???
148+
* @see DATACMNS-332
148149
*/
149150
@Test
150151
public void usesMostConcreteProperty() {
@@ -154,6 +155,22 @@ public void usesMostConcreteProperty() {
154155
assertThat(entity.getPersistentProperty("foo").isIdProperty(), is(true));
155156
}
156157

158+
/**
159+
* @see DATACMNS-345
160+
*/
161+
@Test
162+
@SuppressWarnings("rawtypes")
163+
public void returnsEntityForComponentType() {
164+
165+
SampleMappingContext mappingContext = new SampleMappingContext();
166+
PersistentEntity<Object, SamplePersistentProperty> entity = mappingContext.getPersistentEntity(Sample.class);
167+
SamplePersistentProperty property = entity.getPersistentProperty("persons");
168+
PersistentEntity<Object, SamplePersistentProperty> propertyEntity = mappingContext.getPersistentEntity(property);
169+
170+
assertThat(propertyEntity, is(notNullValue()));
171+
assertThat(propertyEntity.getType(), is(equalTo((Class) Person.class)));
172+
}
173+
157174
class Person {
158175
String name;
159176
}
@@ -165,14 +182,14 @@ class Unsupported {
165182
class Sample {
166183

167184
MetaClass metaClass;
185+
List<Person> persons;
168186
}
169187

170188
static class Base {
171189
String foo;
172190
}
173191

174192
static class Extension extends Base {
175-
@Id
176-
String foo;
193+
@Id String foo;
177194
}
178195
}

0 commit comments

Comments
 (0)