Browse Source

DATAMONGO-638 - MappingContext does not create PersistentEntities for AbstractMaps.

pull/29/merge
Oliver Gierke 13 years ago
parent
commit
0c69c87787
  1. 4
      spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/MongoMappingContext.java
  2. 14
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/mapping/MongoMappingContextUnitTests.java

4
spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/MongoMappingContext.java

@ -17,7 +17,7 @@ package org.springframework.data.mongodb.core.mapping; @@ -17,7 +17,7 @@ package org.springframework.data.mongodb.core.mapping;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.AbstractMap;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
@ -52,7 +52,7 @@ public class MongoMappingContext extends AbstractMappingContext<BasicMongoPersis @@ -52,7 +52,7 @@ public class MongoMappingContext extends AbstractMappingContext<BasicMongoPersis
*/
@Override
protected boolean shouldCreatePersistentEntityFor(TypeInformation<?> type) {
return !MongoSimpleTypes.HOLDER.isSimpleType(type.getType()) && !type.getType().equals(HashMap.class);
return !MongoSimpleTypes.HOLDER.isSimpleType(type.getType()) && !AbstractMap.class.isAssignableFrom(type.getType());
}
/*

14
spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/mapping/MongoMappingContextUnitTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright (c) 2011 by the original author(s).
* Copyright 2011-2013 by the original author(s).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -13,13 +13,13 @@ @@ -13,13 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.mongodb.core.mapping;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import java.lang.reflect.Field;
import java.util.AbstractMap;
import java.util.Collections;
import java.util.Map;
@ -80,6 +80,16 @@ public class MongoMappingContextUnitTests { @@ -80,6 +80,16 @@ public class MongoMappingContextUnitTests {
assertThat(ReflectionUtils.getField(field, context), is(notNullValue()));
}
/**
* @see DATAMONGO-638
*/
@Test
public void doesNotCreatePersistentEntityForAbstractMap() {
MongoMappingContext context = new MongoMappingContext();
assertThat(context.getPersistentEntity(AbstractMap.class), is(nullValue()));
}
class ClassWithMultipleIdProperties {
@Id

Loading…
Cancel
Save