diff --git a/org.springframework.orm/src/main/java/org/springframework/orm/jpa/persistenceunit/DefaultPersistenceUnitManager.java b/org.springframework.orm/src/main/java/org/springframework/orm/jpa/persistenceunit/DefaultPersistenceUnitManager.java index 2afd92abca..36d446b81e 100644 --- a/org.springframework.orm/src/main/java/org/springframework/orm/jpa/persistenceunit/DefaultPersistenceUnitManager.java +++ b/org.springframework.orm/src/main/java/org/springframework/orm/jpa/persistenceunit/DefaultPersistenceUnitManager.java @@ -353,7 +353,7 @@ public class DefaultPersistenceUnitManager } postProcessPersistenceUnitInfo(pui); String name = pui.getPersistenceUnitName(); - if (!this.persistenceUnitInfoNames.add(name)) { + if (!this.persistenceUnitInfoNames.add(name) && !isPersistenceUnitOverrideAllowed()) { StringBuilder msg = new StringBuilder(); msg.append("Conflicting persistence unit definitions for name '").append(name).append("': "); msg.append(pui.getPersistenceUnitRootUrl()).append(", "); @@ -478,7 +478,7 @@ public class DefaultPersistenceUnitManager /** * Hook method allowing subclasses to customize each PersistenceUnitInfo. - *
Default implementation delegates to all registered PersistenceUnitPostProcessors. + *
The default implementation delegates to all registered PersistenceUnitPostProcessors.
* It is usually preferable to register further entity classes, jar files etc there
* rather than in a subclass of this manager, to be able to reuse the post-processors.
* @param pui the chosen PersistenceUnitInfo, as read from persistence.xml
.
@@ -494,6 +494,15 @@ public class DefaultPersistenceUnitManager
}
}
+ /**
+ * Return whether an override of a same-named persistence unit is allowed.
+ *
Default is false
. May be overridden to return true
,
+ * for example if {@link #postProcessPersistenceUnitInfo} is able to handle that case.
+ */
+ protected boolean isPersistenceUnitOverrideAllowed() {
+ return false;
+ }
+
public PersistenceUnitInfo obtainDefaultPersistenceUnitInfo() {
if (this.persistenceUnitInfoNames.isEmpty()) {