/**
* We can't trust the fieldNumber on the ammd provided because some embedded
* fields don't have this set. That's why we pass it in as a separate param.
*/
private Object fetchEmbeddedField(AbstractMemberMetaData ammd, int fieldNumber) {
StateManager esm = getEmbeddedStateManager(ammd, fieldNumber, null);
// We need to build a mapping consumer for the embedded class so that we
// get correct fieldIndex --> metadata mappings for the class in the proper
// embedded context
// TODO(maxr) Consider caching this
InsertMappingConsumer mappingConsumer = buildMappingConsumer(
esm.getClassMetaData(), getClassLoaderResolver(),
esm.getClassMetaData().getAllMemberPositions(),
ammd.getEmbeddedMetaData());
AbstractMemberMetaDataProvider ammdProvider = getEmbeddedAbstractMemberMetaDataProvider(mappingConsumer);
fieldManagerStateStack.addFirst(new FieldManagerState(esm, ammdProvider, mappingConsumer, true));
AbstractClassMetaData acmd = esm.getClassMetaData();
esm.replaceFields(acmd.getAllMemberPositions(), this);
fieldManagerStateStack.removeFirst();
return esm.getObject();
}