@Override
  @SuppressWarnings("unchecked")
  public EntityManagerFactory createContainerEntityManagerFactory(
      PersistenceUnitInfo info, Map properties) {
    final Map settings = generateSettings(properties);

    // OSGi ClassLoaders must implement BundleReference
    settings.put(
        org.hibernate.jpa.AvailableSettings.SCANNER,
        new OsgiScanner(((BundleReference) info.getClassLoader()).getBundle()));

    osgiClassLoader.addClassLoader(info.getClassLoader());

    return Bootstrap.getEntityManagerFactoryBuilder(info, settings, osgiClassLoader).build();
  }
  @Override
  @SuppressWarnings("unchecked")
  public EntityManagerFactory createEntityManagerFactory(
      String persistenceUnitName, Map properties) {
    final Map settings = generateSettings(properties);

    // TODO: This needs tested.
    settings.put(org.hibernate.jpa.AvailableSettings.SCANNER, new OsgiScanner(requestingBundle));
    // TODO: This is temporary -- for PersistenceXmlParser's use of
    // ClassLoaderServiceImpl#fromConfigSettings
    settings.put(AvailableSettings.ENVIRONMENT_CLASSLOADER, osgiClassLoader);

    osgiClassLoader.addBundle(requestingBundle);

    final EntityManagerFactoryBuilder builder =
        getEntityManagerFactoryBuilderOrNull(persistenceUnitName, settings, osgiClassLoader);
    return builder == null ? null : builder.build();
  }