assertTrue( !( ((DBObject)((List)hotelDbObj.get("phoneNumbers")).get(0)).containsField(Mapper.CLASS_NAME_FIELDNAME)) );
hotels.save(hotelDbObj);
Hotel borgLoaded = morphia.fromDBObject(Hotel.class, hotelDbObj, new DefaultEntityCache());
assertEquals(borg.getName(), borgLoaded.getName());
assertEquals(borg.getStars(), borgLoaded.getStars());
assertEquals(borg.getStartDate(), borgLoaded.getStartDate());
assertEquals(borg.getType(), borgLoaded.getType());
assertEquals(borg.getAddress().getStreet(), borgLoaded.getAddress().getStreet());
assertEquals(borg.getTags().size(), borgLoaded.getTags().size());
assertEquals(borg.getTags(), borgLoaded.getTags());
assertEquals(borg.getPhoneNumbers().size(), borgLoaded.getPhoneNumbers().size());
assertEquals(borg.getPhoneNumbers().get(1), borgLoaded.getPhoneNumbers().get(1));
assertNull(borgLoaded.getTemp());
assertTrue(borgLoaded.getPhoneNumbers() instanceof Vector);
assertNotNull(borgLoaded.getId());
TravelAgency agency = new TravelAgency();
agency.setName("Lastminute.com");
agency.getHotels().add(borgLoaded);
BasicDBObject agencyDbObj = (BasicDBObject) morphia.toDBObject(agency);
agencies.save(agencyDbObj);
TravelAgency agencyLoaded = morphia.fromDBObject(TravelAgency.class,
(BasicDBObject) agencies.findOne(new BasicDBObject(Mapper.ID_KEY, agencyDbObj.get(Mapper.ID_KEY))),
new DefaultEntityCache());
assertEquals(agency.getName(), agencyLoaded.getName());
assertEquals(agency.getHotels().size(), 1);
assertEquals(agency.getHotels().get(0).getName(), borg.getName());
// try clearing values
borgLoaded.setAddress(null);
borgLoaded.getPhoneNumbers().clear();
borgLoaded.setName(null);
hotelDbObj = (BasicDBObject) morphia.toDBObject(borgLoaded);
hotels.save(hotelDbObj);
hotelDbObj = (BasicDBObject)hotels.findOne(new BasicDBObject(Mapper.ID_KEY, hotelDbObj.get(Mapper.ID_KEY)));
borgLoaded = morphia.fromDBObject(Hotel.class, hotelDbObj, new DefaultEntityCache());
assertNull(borgLoaded.getAddress());
assertEquals(0, borgLoaded.getPhoneNumbers().size());
assertNull(borgLoaded.getName());
}