Announcement Announcement Module
Collapse
No announcement yet.
Mongodb : is ConverterNotFoundException for composite-id insertion Benign? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Mongodb : is ConverterNotFoundException for composite-id insertion Benign?

    Got the following exception when inserting a document whose id is a composite type:

    org.springframework.core.convert.ConverterNotFound Exception: No converter found capable of converting from type com.mongodb.BasicDBObject<?, ?> to type SnapshotStats$Id

    (Note that the id field is set before the call to mongoTemplate.insert()).

    The record is getting inserted into the database correctly, and am also able to retrieve it correctly. I haven't configured any converters.

    What is the significance of this exception?

    Full stack trace:
    Exception in thread "main" org.springframework.core.convert.ConverterNotFound Exception: No converter found capable of converting from type com.mongodb.BasicDBObject<?, ?> to SnapshotStats$Id
    at org.springframework.core.convert.support.GenericCo nversionService.handleConverterNotFound(GenericCon versionService.java:475)
    at org.springframework.core.convert.support.GenericCo nversionService.convert(GenericConversionService.j ava:175)
    at org.springframework.core.convert.support.GenericCo nversionService.convert(GenericConversionService.j ava:154)
    at org.springframework.data.mapping.model.BeanWrapper .getPotentiallyConvertedValue(BeanWrapper.java:233 )
    at org.springframework.data.mapping.model.BeanWrapper .setProperty(BeanWrapper.java:158)
    at org.springframework.data.mapping.model.BeanWrapper .setProperty(BeanWrapper.java:140)
    at org.springframework.data.mongodb.core.MongoTemplat e.populateIdIfNecessary(MongoTemplate.java:1331)
    at org.springframework.data.mongodb.core.MongoTemplat e.doInsert(MongoTemplate.java:620)
    at org.springframework.data.mongodb.core.MongoTemplat e.insert(MongoTemplate.java:577)
    at test.FooTest2.work2(FooTest2.java:104)
    at test.FooTest2.main(FooTest2.java:59)

  • #2
    Would you mind posting the SnapshotStats class as well as the document as it resides in the MongoDB?

    Comment


    • #3
      Following is a simpler test class of the scenario.

      Data class (instead of Snapshots in original post):
      Code:
      public class Data {
      
      	public static class Id {
      		@Field("x")
      		private long x;
      
      		@Field("t")
      		private Date t = new Date();
      
      		@Override
      		public String toString() {
      			return "Id [x=" + x + ", t=" + t + "]";
      		}
      
      	}
      
      	private Id id = new Id();
      
      	private int i;
      
      	@Override
      	public String toString() {
      		return "Data [id=" + id + ", i=" + i + "]";
      	}
      
      }
      ---------------------------------
      FooTest2.main():
      Code:
      {
      		System.out.println(mongoTemplate);
      		Data data = new Data();
      		try {
      			mongoTemplate.insert(data);
      		} catch (ConverterNotFoundException e) {
      			e.printStackTrace();
      		}
      
      		data = mongoTemplate.findOne(new Query(), Data.class);
      		System.out.println(data);
      
      		System.out.println("Fooo..... ");
      }
      -------------------
      Console output:

      org.springframework.data.mongodb.core.MongoTemplat e@2804f2ec
      org.springframework.core.convert.ConverterNotFound Exception: No converter found capable of converting from type com.mongodb.BasicDBObject<?, ?> to type test.Data$Id
      at org.springframework.core.convert.support.GenericCo nversionService.handleConverterNotFound(GenericCon versionService.java:475)
      at org.springframework.core.convert.support.GenericCo nversionService.convert(GenericConversionService.j ava:175)
      at org.springframework.core.convert.support.GenericCo nversionService.convert(GenericConversionService.j ava:154)
      at org.springframework.data.mapping.model.BeanWrapper .getPotentiallyConvertedValue(BeanWrapper.java:233 )
      at org.springframework.data.mapping.model.BeanWrapper .setProperty(BeanWrapper.java:158)
      at org.springframework.data.mapping.model.BeanWrapper .setProperty(BeanWrapper.java:140)
      at org.springframework.data.mongodb.core.MongoTemplat e.populateIdIfNecessary(MongoTemplate.java:1331)
      at org.springframework.data.mongodb.core.MongoTemplat e.doInsert(MongoTemplate.java:620)
      at org.springframework.data.mongodb.core.MongoTemplat e.insert(MongoTemplate.java:577)
      at org.springframework.data.mongodb.core.MongoTemplat e.insert(MongoTemplate.java:568)
      at test.FooTest2.work(FooTest2.java:78)
      at test.FooTest2.main(FooTest2.java:51)
      Data [id=Id [x=0, t=Thu Mar 22 00:35:56 PDT 2012], i=0]
      Fooo.....
      ------------------------------
      Mongo:
      > db.data.find()
      { "_id" : { "x" : NumberLong(0), "t" : ISODate("2012-03-22T07:35:56.405Z") }, "i" : 0 }

      ------
      More inserts (reruns of FooTest2.main() ) also work fine.

      Comment

      Working...
      X