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.
This commit is contained in:
committed by
Oliver Gierke
parent
8eb6030fc0
commit
51aca33cc6
@@ -181,12 +181,8 @@ public abstract class AbstractMappingContext<E extends MutablePersistentEntity<?
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
read.lock();
|
||||
return persistentEntities.get(persistentProperty.getTypeInformation());
|
||||
} finally {
|
||||
read.unlock();
|
||||
}
|
||||
TypeInformation<?> typeInfo = persistentProperty.getTypeInformation();
|
||||
return getPersistentEntity(typeInfo.getActualType());
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -21,6 +21,7 @@ import static org.mockito.Mockito.*;
|
||||
import groovy.lang.MetaClass;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -144,7 +145,7 @@ public class AbstractMappingContextUnitTests {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-???
|
||||
* @see DATACMNS-332
|
||||
*/
|
||||
@Test
|
||||
public void usesMostConcreteProperty() {
|
||||
@@ -154,6 +155,22 @@ public class AbstractMappingContextUnitTests {
|
||||
assertThat(entity.getPersistentProperty("foo").isIdProperty(), is(true));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-345
|
||||
*/
|
||||
@Test
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void returnsEntityForComponentType() {
|
||||
|
||||
SampleMappingContext mappingContext = new SampleMappingContext();
|
||||
PersistentEntity<Object, SamplePersistentProperty> entity = mappingContext.getPersistentEntity(Sample.class);
|
||||
SamplePersistentProperty property = entity.getPersistentProperty("persons");
|
||||
PersistentEntity<Object, SamplePersistentProperty> propertyEntity = mappingContext.getPersistentEntity(property);
|
||||
|
||||
assertThat(propertyEntity, is(notNullValue()));
|
||||
assertThat(propertyEntity.getType(), is(equalTo((Class) Person.class)));
|
||||
}
|
||||
|
||||
class Person {
|
||||
String name;
|
||||
}
|
||||
@@ -165,6 +182,7 @@ public class AbstractMappingContextUnitTests {
|
||||
class Sample {
|
||||
|
||||
MetaClass metaClass;
|
||||
List<Person> persons;
|
||||
}
|
||||
|
||||
static class Base {
|
||||
@@ -172,7 +190,6 @@ public class AbstractMappingContextUnitTests {
|
||||
}
|
||||
|
||||
static class Extension extends Base {
|
||||
@Id
|
||||
String foo;
|
||||
@Id String foo;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user