if (rootUrl.endsWith(".war")) {
rootUrl = rootUrl.substring(0, rootUrl.length() - ".war".length());
}
try {
Persistence persistence = JaxbPersistenceFactory.getPersistence(Persistence.class, persistenceUrl);
PersistenceModule persistenceModule = new PersistenceModule(rootUrl, persistence);
persistenceModule.getWatchedResources().add(moduleName);
if ("file".equals(persistenceUrl.getProtocol())) {
persistenceModule.getWatchedResources().add(path);
}
appModule.getPersistenceModules().add(persistenceModule);
} catch (Exception e1) {
DeploymentLoader.logger.error("Unable to load Persistence Unit from EAR: " + appModule.getJarLocation() + ", module: " + moduleName + ". Exception: " + e1.getMessage(), e1);
}
}
}
final List<URL> persistenceFragmentUrls = (List<URL>) appModule.getAltDDs().get("persistence-fragment.xml");
if (persistenceFragmentUrls != null) {
for (URL persistenceFragmentUrl : persistenceFragmentUrls) {
try {
final PersistenceFragment persistenceFragment = JaxbPersistenceFactory.getPersistence(PersistenceFragment.class, persistenceFragmentUrl);
// merging
for (PersistenceUnitFragment fragmentUnit : persistenceFragment.getPersistenceUnitFragment()) {
for (PersistenceModule persistenceModule : appModule.getPersistenceModules()) {
final Persistence persistence = persistenceModule.getPersistence();
for (PersistenceUnit unit : persistence.getPersistenceUnit()) {
if (!fragmentUnit.getName().equals(unit.getName())) {
continue;
}
if (!persistenceFragment.getVersion().equals(persistence.getVersion())) {
logger.error("persistence unit version and fragment version are different, fragment will be ignored");
continue;
}
if ("file".equals(persistenceFragmentUrl.getProtocol())) {