spring-data-mongodb : 1.0.4.RELEASE
I have this scenario with :
1) insert a soup record + it's cinnamon spice
2) find & modify the soup's to use a new spice instead : pepper spice
3) load the soup from db, but the spice is now 'typeless', instanceof pepper spice returns false
Let's jump to the simple codes and the record output from mongo shell as it changes :
1) insert a soup record + it's cinnamon spice
2) find & modify the soup's to use a new spice instead : pepper spiceCode:// insert a cinnamon soup SlurpSoup soup = new SlurpSoup(new CinnamonSpice()); this.ops.insert(soup, collectionName); /* > db.testUpdate.find().pretty(); { "_id" : "6cdf40c1-1730-4d23-a94b-e461fbfc2f65", "_class" : "lab.convert.SlurpSoup", "spice" : { "_class" : "lab.convert.SlurpSoup$CinnamonSpice", "label" : "cinnamon" } } */ // load the soup, and check the spice type, should be a cinnamon spice type SlurpSoup loadedFromDb = this.ops.findById(soup.getId(), SlurpSoup.class, collectionName); Assert.isTrue(loadedFromDb.getSpice() instanceof CinnamonSpice, "should be a cinnamon spice !");
3) load the soup from db, but the spice is now 'typeless', instanceof peper spice returns falseCode:// change the spice this.ops.findAndModify( Query.query(Criteria.where("_id").is(soup.getId())), // get the created soup Update.update("spice", new PepperSpice()), // re-set the spice type SlurpSoup.class, collectionName ); /* > db.testUpdate.find().pretty(); { "_class" : "lab.convert.SlurpSoup", "_id" : "6cdf40c1-1730-4d23-a94b-e461fbfc2f65", "spice" : { "label" : "pepper" } } */
The complete sources and context file is attached.Code:// reload the soup, and re-check the spice type, now should be a pepper spice type loadedFromDb = this.ops.findById(soup.getId(), SlurpSoup.class, collectionName); Assert.isTrue(loadedFromDb.getSpice() instanceof PepperSpice, "should be a pepper spice !"); /* Exception in thread "main" java.lang.IllegalArgumentException: should be a pepper spice ! at org.springframework.util.Assert.isTrue(Assert.java:65) at lab.convert.TestUpdate.test(TestUpdate.java:65) at lab.convert.TestUpdate.main(TestUpdate.java:27) */
Is this a (reported) bug ?


Reply With Quote
