Skip to content

Commit 103c648

Browse files
jhoellercbeams
authored andcommitted
added protected "isPersistenceUnitOverrideAllowed()" method to DefaultPersistenceUnitManager (SPR-8925)
1 parent e0252ad commit 103c648

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

org.springframework.orm/src/main/java/org/springframework/orm/jpa/persistenceunit/DefaultPersistenceUnitManager.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ public void preparePersistenceUnitInfos() {
353353
}
354354
postProcessPersistenceUnitInfo(pui);
355355
String name = pui.getPersistenceUnitName();
356-
if (!this.persistenceUnitInfoNames.add(name)) {
356+
if (!this.persistenceUnitInfoNames.add(name) && !isPersistenceUnitOverrideAllowed()) {
357357
StringBuilder msg = new StringBuilder();
358358
msg.append("Conflicting persistence unit definitions for name '").append(name).append("': ");
359359
msg.append(pui.getPersistenceUnitRootUrl()).append(", ");
@@ -478,7 +478,7 @@ protected final MutablePersistenceUnitInfo getPersistenceUnitInfo(String persist
478478

479479
/**
480480
* Hook method allowing subclasses to customize each PersistenceUnitInfo.
481-
* <p>Default implementation delegates to all registered PersistenceUnitPostProcessors.
481+
* <p>The default implementation delegates to all registered PersistenceUnitPostProcessors.
482482
* It is usually preferable to register further entity classes, jar files etc there
483483
* rather than in a subclass of this manager, to be able to reuse the post-processors.
484484
* @param pui the chosen PersistenceUnitInfo, as read from <code>persistence.xml</code>.
@@ -494,6 +494,15 @@ protected void postProcessPersistenceUnitInfo(MutablePersistenceUnitInfo pui) {
494494
}
495495
}
496496

497+
/**
498+
* Return whether an override of a same-named persistence unit is allowed.
499+
* <p>Default is <code>false</code>. May be overridden to return <code>true</code>,
500+
* for example if {@link #postProcessPersistenceUnitInfo} is able to handle that case.
501+
*/
502+
protected boolean isPersistenceUnitOverrideAllowed() {
503+
return false;
504+
}
505+
497506

498507
public PersistenceUnitInfo obtainDefaultPersistenceUnitInfo() {
499508
if (this.persistenceUnitInfoNames.isEmpty()) {

0 commit comments

Comments
 (0)