Metadata factory and EntityMetadata fixes