private Map<EntityKeyMetadata, EmbeddedNeo4jEntityQueries> initializeEntityQueries(
     SessionFactoryImplementor sessionFactoryImplementor) {
   Map<EntityKeyMetadata, EmbeddedNeo4jEntityQueries> queryMap =
       new HashMap<EntityKeyMetadata, EmbeddedNeo4jEntityQueries>();
   Collection<EntityPersister> entityPersisters =
       sessionFactoryImplementor.getEntityPersisters().values();
   for (EntityPersister entityPersister : entityPersisters) {
     if (entityPersister instanceof OgmEntityPersister) {
       OgmEntityPersister ogmEntityPersister = (OgmEntityPersister) entityPersister;
       queryMap.put(
           ogmEntityPersister.getEntityKeyMetadata(),
           new EmbeddedNeo4jEntityQueries(ogmEntityPersister.getEntityKeyMetadata()));
     }
   }
   return queryMap;
 }
  private EntityMetadataInformation determineSingleEntityMetadataInformation(
      SessionFactoryImplementor sessionFactory, List<Return> customQueryReturns) {
    EntityMetadataInformation metadataInformation = null;

    for (Return queryReturn : customQueryReturns) {
      if (queryReturn instanceof RootReturn) {
        if (metadataInformation != null) {
          return null;
        }
        RootReturn rootReturn = (RootReturn) queryReturn;
        OgmEntityPersister persister =
            (OgmEntityPersister) sessionFactory.getEntityPersister(rootReturn.getEntityName());
        metadataInformation =
            new EntityMetadataInformation(
                persister.getEntityKeyMetadata(), rootReturn.getEntityName());
      }
    }

    return metadataInformation;
  }
  private static EntityKeyMetadata determineSingleEntityKeyMetadata(
      SessionFactoryImplementor sessionFactory, List<Return> customQueryReturns) {
    EntityKeyMetadata metadata = null;

    for (Return queryReturn : customQueryReturns) {
      if (queryReturn instanceof RootReturn) {
        if (metadata != null) {
          return null;
        }
        RootReturn rootReturn = (RootReturn) queryReturn;
        OgmEntityPersister persister =
            (OgmEntityPersister) sessionFactory.getEntityPersister(rootReturn.getEntityName());
        metadata =
            new DefaultEntityKeyMetadata(
                persister.getTableName(), persister.getRootTableIdentifierColumnNames());
      }
    }

    return metadata;
  }