diff --git a/org.springframework.orm/src/main/java/org/springframework/orm/jpa/LocalContainerEntityManagerFactoryBean.java b/org.springframework.orm/src/main/java/org/springframework/orm/jpa/LocalContainerEntityManagerFactoryBean.java index 6774691c979..da80e700099 100644 --- a/org.springframework.orm/src/main/java/org/springframework/orm/jpa/LocalContainerEntityManagerFactoryBean.java +++ b/org.springframework.orm/src/main/java/org/springframework/orm/jpa/LocalContainerEntityManagerFactoryBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2012 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -123,6 +123,17 @@ public class LocalContainerEntityManagerFactoryBean extends AbstractEntityManage this.internalPersistenceUnitManager.setPersistenceXmlLocation(persistenceXmlLocation); } + /** + * Uses the specified persistence unit name as the name of the default + * persistence unit, if applicable. + *
NOTE: Only applied if no external PersistenceUnitManager specified.
+ */
+ @Override
+ public void setPersistenceUnitName(String persistenceUnitName) {
+ super.setPersistenceUnitName(persistenceUnitName);
+ this.internalPersistenceUnitManager.setDefaultPersistenceUnitName(persistenceUnitName);
+ }
+
/**
* Set whether to use Spring-based scanning for entity classes in the classpath
* instead of using JPA's standard scanning of jar files with persistence.xml
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 36d446b81e1..807b8ae2d7f 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
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2011 the original author or authors.
+ * Copyright 2002-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -55,6 +55,7 @@ import org.springframework.jdbc.datasource.lookup.JndiDataSourceLookup;
import org.springframework.jdbc.datasource.lookup.MapDataSourceLookup;
import org.springframework.util.ClassUtils;
import org.springframework.util.ObjectUtils;
+import org.springframework.util.ResourceUtils;
/**
* Default implementation of the {@link PersistenceUnitManager} interface.
@@ -328,7 +329,7 @@ public class DefaultPersistenceUnitManager
/**
* Prepare the PersistenceUnitInfos according to the configuration
* of this manager: scanning for persistence.xml files,
- * parsing all matching files, configurating and post-processing them.
+ * parsing all matching files, configuring and post-processing them.
*
PersistenceUnitInfos cannot be obtained before this preparation
* method has been invoked.
* @see #obtainDefaultPersistenceUnitInfo()
@@ -404,6 +405,12 @@ public class DefaultPersistenceUnitManager
String className = reader.getClassMetadata().getClassName();
if (matchesFilter(reader, readerFactory)) {
scannedUnit.addManagedClassName(className);
+ if (scannedUnit.getPersistenceUnitRootUrl() == null) {
+ URL url = resource.getURL();
+ if (ResourceUtils.isJarURL(url)) {
+ scannedUnit.setPersistenceUnitRootUrl(ResourceUtils.extractJarFileURL(url));
+ }
+ }
}
}
}
diff --git a/org.springframework.orm/src/main/java/org/springframework/orm/jpa/persistenceunit/PersistenceUnitReader.java b/org.springframework.orm/src/main/java/org/springframework/orm/jpa/persistenceunit/PersistenceUnitReader.java
index f8d474ea18f..d2460ec94c1 100644
--- a/org.springframework.orm/src/main/java/org/springframework/orm/jpa/persistenceunit/PersistenceUnitReader.java
+++ b/org.springframework.orm/src/main/java/org/springframework/orm/jpa/persistenceunit/PersistenceUnitReader.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2010 the original author or authors.
+ * Copyright 2002-2012 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -43,7 +43,7 @@ import org.springframework.util.xml.DomUtils;
import org.springframework.util.xml.SimpleSaxErrorHandler;
/**
- * Internal helper class for reading persistence.xml files.
+ * Internal helper class for reading JPA-compliant persistence.xml files.
*
* @author Costin Leau
* @author Juergen Hoeller
@@ -227,7 +227,7 @@ class PersistenceUnitReader {
/**
* Parse the unit info DOM element.
*/
- protected SpringPersistenceUnitInfo parsePersistenceUnitInfo(Element persistenceUnit, String version) throws IOException { // JC: Changed
+ protected SpringPersistenceUnitInfo parsePersistenceUnitInfo(Element persistenceUnit, String version) throws IOException {
SpringPersistenceUnitInfo unitInfo = new SpringPersistenceUnitInfo();
// set JPA version (1.0 or 2.0)
diff --git a/org.springframework.orm/src/test/java/org/springframework/orm/jpa/eclipselink/eclipselink-manager.xml b/org.springframework.orm/src/test/java/org/springframework/orm/jpa/eclipselink/eclipselink-manager.xml
index 625605e8278..a2e4f06ab81 100644
--- a/org.springframework.orm/src/test/java/org/springframework/orm/jpa/eclipselink/eclipselink-manager.xml
+++ b/org.springframework.orm/src/test/java/org/springframework/orm/jpa/eclipselink/eclipselink-manager.xml
@@ -5,6 +5,10 @@