Browse Source

LocalContainerEntityManagerFactoryBean's "persistenceUnitName" applies to "packagesToScan" as well; DefaultPersistenceUnitManager uses containing jar as persistence unit root URL for default unit (SPR-8832)

pull/16/merge
Juergen Hoeller 13 years ago
parent
commit
62e5b9da04
  1. 13
      org.springframework.orm/src/main/java/org/springframework/orm/jpa/LocalContainerEntityManagerFactoryBean.java
  2. 11
      org.springframework.orm/src/main/java/org/springframework/orm/jpa/persistenceunit/DefaultPersistenceUnitManager.java
  3. 6
      org.springframework.orm/src/main/java/org/springframework/orm/jpa/persistenceunit/PersistenceUnitReader.java
  4. 4
      org.springframework.orm/src/test/java/org/springframework/orm/jpa/eclipselink/eclipselink-manager.xml

13
org.springframework.orm/src/main/java/org/springframework/orm/jpa/LocalContainerEntityManagerFactoryBean.java

@ -1,5 +1,5 @@ @@ -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 @@ -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.
* <p><b>NOTE: Only applied if no external PersistenceUnitManager specified.</b>
*/
@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 <code>persistence.xml</code>

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

@ -1,5 +1,5 @@ @@ -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; @@ -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 @@ -328,7 +329,7 @@ public class DefaultPersistenceUnitManager
/**
* Prepare the PersistenceUnitInfos according to the configuration
* of this manager: scanning for <code>persistence.xml</code> files,
* parsing all matching files, configurating and post-processing them.
* parsing all matching files, configuring and post-processing them.
* <p>PersistenceUnitInfos cannot be obtained before this preparation
* method has been invoked.
* @see #obtainDefaultPersistenceUnitInfo()
@ -404,6 +405,12 @@ public class DefaultPersistenceUnitManager @@ -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));
}
}
}
}
}

6
org.springframework.orm/src/main/java/org/springframework/orm/jpa/persistenceunit/PersistenceUnitReader.java

@ -1,5 +1,5 @@ @@ -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; @@ -43,7 +43,7 @@ import org.springframework.util.xml.DomUtils;
import org.springframework.util.xml.SimpleSaxErrorHandler;
/**
* Internal helper class for reading <code>persistence.xml</code> files.
* Internal helper class for reading JPA-compliant <code>persistence.xml</code> files.
*
* @author Costin Leau
* @author Juergen Hoeller
@ -227,7 +227,7 @@ class PersistenceUnitReader { @@ -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)

4
org.springframework.orm/src/test/java/org/springframework/orm/jpa/eclipselink/eclipselink-manager.xml

@ -5,6 +5,10 @@ @@ -5,6 +5,10 @@
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceXmlLocation" value="org/springframework/orm/jpa/domain/persistence.xml"/>
<!--
<property name="persistenceUnitName" value="Person"/>
<property name="packagesToScan" value="org.springframework.orm.jpa.domain"/>
-->
<property name="dataSource" ref="dataSource"/>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter">

Loading…
Cancel
Save