LocalContainerEntityManagerFactoryBean's "persistenceUnitName" applies to "packagesToScan" as well; DefaultPersistenceUnitManager uses containing jar as persistence unit root URL for default unit (SPR-8832)
This commit is contained in:
parent
f367619b0c
commit
62e5b9da04
|
|
@ -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.
|
||||
* <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>
|
||||
|
|
|
|||
|
|
@ -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 <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
|
|||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 <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 {
|
|||
/**
|
||||
* 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)
|
||||
|
|
|
|||
|
|
@ -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…
Reference in New Issue