}
TypeMetadataSet<?> types = metadataProvider.getTypes(discriminators);
EntityId id = datastoreSession.getId(entity);
Object instance = cache.get(id);
if (instance == null) {
InstanceInvocationHandler invocationHandler = new InstanceInvocationHandler(entity, proxyMethodService);
instance = createInstance(invocationHandler, types.toClasses(), CompositeObject.class);
cache.put(id, instance);
}
return (T) instance;
}