public EntityManagerFactory call() throws Exception {
final ClassLoader old = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(appClassLoader);
try {
final Class<?> clazz = appClassLoader.loadClass(persistenceProviderClassName);
final PersistenceProvider persistenceProvider = (PersistenceProvider) clazz.newInstance();
// Create entity manager factories with the validator factory
final Map<String, Object> properties = new HashMap<String, Object>();
if (!ValidationMode.NONE.equals(unitInfo.getValidationMode())) {
properties.put("javax.persistence.validator.ValidatorFactory", new ValidatorFactoryWrapper());
}
customizeProperties(properties);
final EntityManagerFactory emf = persistenceProvider.createContainerEntityManagerFactory(unitInfo, properties);
if (unitInfo.getProperties() != null
&& "true".equalsIgnoreCase(unitInfo.getProperties().getProperty(OPENEJB_JPA_INIT_ENTITYMANAGER))
|| SystemInstance.get().getOptions().get(OPENEJB_JPA_INIT_ENTITYMANAGER, false)) {
emf.createEntityManager().close();