in transform/src/patch/java/org/apache/openjpa/persistence/PersistenceProviderImpl.java [86:136]
public OpenJPAEntityManagerFactory createEntityManagerFactory(String name, String resource, Map m) {
PersistenceProductDerivation pd = new PersistenceProductDerivation();
try {
Object poolValue = Configurations.removeProperty(EMF_POOL, m);
ConfigurationProvider cp = pd.load(resource, name, m);
if (cp == null) {
return null;
}
BrokerFactory factory = getBrokerFactory(cp, poolValue, BundleUtils.getBundleClassLoader());
OpenJPAConfiguration conf = factory.getConfiguration();
conf.setUserClassLoader(BundleUtils.getBundleClassLoader());
_log = conf.getLog(OpenJPAConfiguration.LOG_RUNTIME);
pd.checkPuNameCollisions(_log,name);
// add enhancer
loadAgent(factory);
// Create appropriate LifecycleEventManager
loadValidator(factory);
if (conf.getConnectionRetainModeConstant() == ConnectionRetainModes.CONN_RETAIN_ALWAYS) {
// warn about EMs holding on to connections.
_log.warn(_loc.get("retain-always", conf.getId()));
}
OpenJPAEntityManagerFactory emf = JPAFacadeHelper.toEntityManagerFactory(factory);
if (_log.isTraceEnabled()) {
_log.trace(this + " creating " + emf + " for PU " + name + ".");
}
return emf;
} catch (Exception e) {
if (_log != null) {
_log.error(_loc.get("create-emf-error", name), e);
}
/*
*
* Maintain 1.x behavior of throwing exceptions, even though
* JPA2 9.2 - createEMF "must" return null for PU it can't handle.
*
* JPA 2.0 Specification Section 9.2 states:
* "If a provider does not qualify as the provider for the named persistence unit,
* it must return null when createEntityManagerFactory is invoked on it."
* That specification compliance behavior has happened few lines above on null return.
* Throwing runtime exception in the following code is valid (and useful) behavior
* because the qualified provider has encountered an unexpected situation.
*/
throw PersistenceExceptions.toPersistenceException(e);
}
}