org.springframework.data.mapping.model.MappingException: No mapping metadata found for class com.mongodb.BasicDBObject

There are no available Samebug tips for this exception. Do you have an idea how to solve this issue? A short tip would help users who saw this issue last week.

  • For repository method definition like below: {code:java} @Query("{meanings: {$not: {$size: 0}}}") Page<Entry> findAllWithMeanings(Pageable pageable); {code} Entry documents contain {{meanings}} field which is a list of {{@DBRef}} s. When I remove {{@DBRef}} annotation it works ok, but otherwise I get the following exception: {noformat} Exception in thread "main" org.springframework.data.mapping.model.MappingException: No mapping metadata found for class com.mongodb.BasicDBObject at org.springframework.data.mongodb.core.convert.MappingMongoConverter.createDBRef(MappingMongoConverter.java:729) at org.springframework.data.mongodb.core.convert.MappingMongoConverter.toDBRef(MappingMongoConverter.java:288) at org.springframework.data.mongodb.core.convert.QueryMapper.convertAssociation(QueryMapper.java:273) at org.springframework.data.mongodb.core.convert.QueryMapper.getMappedKeyword(QueryMapper.java:158) at org.springframework.data.mongodb.core.convert.QueryMapper.getMappedObject(QueryMapper.java:111) at org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:1489) at org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:1480) at org.springframework.data.mongodb.core.MongoTemplate.find(MongoTemplate.java:527) at org.springframework.data.mongodb.repository.query.AbstractMongoQuery$PagedExecution.execute(AbstractMongoQuery.java:205) at org.springframework.data.mongodb.repository.query.AbstractMongoQuery.execute(AbstractMongoQuery.java:93) at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:337) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204) … {noformat}
    via by Marcin Kowalski,
  • For repository method definition like below: {code:java} @Query("{meanings: {$not: {$size: 0}}}") Page<Entry> findAllWithMeanings(Pageable pageable); {code} Entry documents contain {{meanings}} field which is a list of {{@DBRef}} s. When I remove {{@DBRef}} annotation it works ok, but otherwise I get the following exception: {noformat} Exception in thread "main" org.springframework.data.mapping.model.MappingException: No mapping metadata found for class com.mongodb.BasicDBObject at org.springframework.data.mongodb.core.convert.MappingMongoConverter.createDBRef(MappingMongoConverter.java:729) at org.springframework.data.mongodb.core.convert.MappingMongoConverter.toDBRef(MappingMongoConverter.java:288) at org.springframework.data.mongodb.core.convert.QueryMapper.convertAssociation(QueryMapper.java:273) at org.springframework.data.mongodb.core.convert.QueryMapper.getMappedKeyword(QueryMapper.java:158) at org.springframework.data.mongodb.core.convert.QueryMapper.getMappedObject(QueryMapper.java:111) at org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:1489) at org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:1480) at org.springframework.data.mongodb.core.MongoTemplate.find(MongoTemplate.java:527) at org.springframework.data.mongodb.repository.query.AbstractMongoQuery$PagedExecution.execute(AbstractMongoQuery.java:205) at org.springframework.data.mongodb.repository.query.AbstractMongoQuery.execute(AbstractMongoQuery.java:93) at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:337) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204) … {noformat}
    via by Marcin Kowalski,
  • Excluding a field in a query where the field is a DBRef as below throws a MappingException. Query query = new Query(Criteria.where("parentField").is("test")); query.fields().exclude("children"); ParentClass parentClass = mongoOperations.findOne(query, ParentClass.class); Exception trace: org.springframework.data.mapping.model.MappingException: No mapping metadata found for class java.lang.Integer at org.springframework.data.mongodb.core.convert.MappingMongoConverter.createDBRef(MappingMongoConverter.java:729) at com.digitalshadows.collation.persistence.impl.CollectionNameProvidedMongoConverter.createDBRef(CollectionNameProvidedMongoConverter.java:28) at org.springframework.data.mongodb.core.convert.MappingMongoConverter.toDBRef(MappingMongoConverter.java:288) at org.springframework.data.mongodb.core.convert.QueryMapper.convertAssociation(QueryMapper.java:273) at org.springframework.data.mongodb.core.convert.QueryMapper.getMappedValue(QueryMapper.java:204) at org.springframework.data.mongodb.core.convert.QueryMapper.getMappedObject(QueryMapper.java:113) at org.springframework.data.mongodb.core.MongoTemplate.doFindOne(MongoTemplate.java:1439) at org.springframework.data.mongodb.core.MongoTemplate.findOne(MongoTemplate.java:489) at org.springframework.data.mongodb.core.MongoTemplate.findOne(MongoTemplate.java:484) at ExcludeDBRefFieldTest.testExcludeChildren(ExcludeDBRefFieldTest.java:28) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20) at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74) at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83) at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:88) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222) at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71) at org.junit.runners.ParentRunner.run(ParentRunner.java:300) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) I've attached a simple test case that throws the MappingException. The workaround for this I can currently see is to use include for all the other fields instead.
    via by Catherine Howe,
  • Using {noformat} @Query(fields="{property3:1}") {noformat} or query object itself {noformat} query.fields().include("property3") {noformat} will fail if the filed has @DBref annotation (with or without @Field) eg.: {noformat} class A { @Id String id; @Field("prop1") String property1; @Field("prop2") String property2; @Field("prop3") @DBRef B property3; } class B { @Id String id; } {noformat} will throw {noformat} org.springframework.data.mapping.model.MappingException: No mapping metadata found for class java.lang.Integer at org.springframework.data.mongodb.core.convert.MappingMongoConverter.createDBRef(MappingMongoConverter.java:729) ~[spring-data-mongodb-1.3.1.RELEASE.jar:na] at org.springframework.data.mongodb.core.convert.MappingMongoConverter.toDBRef(MappingMongoConverter.java:288) ~[spring-data-mongodb-1.3.1.RELEASE.jar:na] at org.springframework.data.mongodb.core.convert.QueryMapper.convertAssociation(QueryMapper.java:272) ~[spring-data-mongodb-1.3.1.RELEASE.jar:na] at org.springframework.data.mongodb.core.convert.QueryMapper.getMappedValue(QueryMapper.java:203) ~[spring-data-mongodb-1.3.1.RELEASE.jar:na] at org.springframework.data.mongodb.core.convert.QueryMapper.getMappedObject(QueryMapper.java:114) ~[spring-data-mongodb-1.3.1.RELEASE.jar:na] at org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:1479) ~[spring-data-mongodb-1.3.1.RELEASE.jar:na] at org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:1471) ~[spring-data-mongodb-1.3.1.RELEASE.jar:na] {noformat} This issue is related to [DATAMONGO-702|https://jira.springsource.org/browse/DATAMONGO-702]
    via by Matej Zachar,
  • There is a model is like: {code:java} class Model { .... @DBRef List<OtherModel> members; ... } {code} and I need sliced access to the members variable. I use this query: {code:java} ObjectId objectId = new ObjectId("55c36f44f359d8a455a21f68"); Query query = new Query(Criteria.where("_id").is(objectId)); query.fields().slice("members", pageable.getOffset(), pageable.getPageSize()); List<Model> models = mongoTemplate.findOne(query, Model.class); {code} And I get this exception: {code:java} org.springframework.data.mapping.model.MappingException: No id property found on class class [Ljava.lang.Integer; at org.springframework.data.mongodb.core.convert.MappingMongoConverter.createDBRef(MappingMongoConverter.java:842) at org.springframework.data.mongodb.core.convert.MappingMongoConverter.toDBRef(MappingMongoConverter.java:329) at org.springframework.data.mongodb.core.convert.QueryMapper.createDbRefFor(QueryMapper.java:460) at org.springframework.data.mongodb.core.convert.QueryMapper.convertAssociation(QueryMapper.java:417) at org.springframework.data.mongodb.core.convert.QueryMapper.convertAssociation(QueryMapper.java:378) at org.springframework.data.mongodb.core.convert.QueryMapper.getMappedKeyword(QueryMapper.java:257) at org.springframework.data.mongodb.core.convert.QueryMapper.getMappedObjectForField(QueryMapper.java:200) at org.springframework.data.mongodb.core.convert.QueryMapper.getMappedObject(QueryMapper.java:123) at org.springframework.data.mongodb.core.MongoTemplate.doFindOne(MongoTemplate.java:1647) at org.springframework.data.mongodb.core.MongoTemplate.findOne(MongoTemplate.java:563) at org.springframework.data.mongodb.core.MongoTemplate.findOne(MongoTemplate.java:558) {code} where a field: {code:java} boolean needsAssociationConversion = property.isAssociation() && !keyword.isExists(); {code} is set. It checks against isExists, but not against something like isSliced (which does not yet exist) and therefore is evaluated to true and, as a cause, tries to convert the non-existing association which is, in this case, just the slice-directive (an integer array). When I set the variable needsAssociationConversion to false while debugging, as if a kind of {code:java} keyword.isSlice() {code} check was done, everything works fine.
    via by Zhu Hongshang,
    • org.springframework.data.mapping.model.MappingException: No mapping metadata found for class com.mongodb.BasicDBObject at org.springframework.data.mongodb.core.convert.MappingMongoConverter.createDBRef(MappingMongoConverter.java:729) at org.springframework.data.mongodb.core.convert.MappingMongoConverter.toDBRef(MappingMongoConverter.java:288) at org.springframework.data.mongodb.core.convert.QueryMapper.convertAssociation(QueryMapper.java:273) at org.springframework.data.mongodb.core.convert.QueryMapper.getMappedKeyword(QueryMapper.java:158) at org.springframework.data.mongodb.core.convert.QueryMapper.getMappedObject(QueryMapper.java:111) at org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:1489) at org.springframework.data.mongodb.core.MongoTemplate.doFind(MongoTemplate.java:1480) at org.springframework.data.mongodb.core.MongoTemplate.find(MongoTemplate.java:527) at org.springframework.data.mongodb.repository.query.AbstractMongoQuery$PagedExecution.execute(AbstractMongoQuery.java:205) at org.springframework.data.mongodb.repository.query.AbstractMongoQuery.execute(AbstractMongoQuery.java:93) at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:337) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)

    Users with the same issue

    Unknown visitor1 times, last one,
    Unknown visitor1 times, last one,
    Unknown visitor1 times, last one,