Parse JPA <exclude-unlisted-classes> correctly

Fix PersistenceUnitReader to correctly read <exclude-unlisted-classes>
in both JPA 1.0 and 2.0 persistence.xml files.

Prior to this commit PersistenceUnitReader would set the value of
excludeUnlistedClasses to true when a <exclude-unlisted-classes> element
was present, regardless of its value.

The following rules are now used when parsing:

- If the <exclude-unlisted-classes> element is missing the appropriate
  default value is set (based on the JPA version).

- If an empty <exclude-unlisted-classes/> element is found the
  excludeUnlistedClasses property is set to true.

- Otherwise the value of the <exclude-unlisted-classes> element is used
  to set the excludeUnlistedClasses property.

Issue: SPR-10767
This commit is contained in:
Nick Williams
2013-07-22 13:26:35 -05:00
committed by Phillip Webb
parent 66cfe9f0e6
commit 7ad540d97b
4 changed files with 131 additions and 4 deletions

View File

@@ -21,6 +21,7 @@ import java.io.InputStream;
import java.net.URL;
import java.util.LinkedList;
import java.util.List;
import javax.persistence.SharedCacheMode;
import javax.persistence.ValidationMode;
import javax.persistence.spi.PersistenceUnitTransactionType;
@@ -34,7 +35,6 @@ import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.jdbc.datasource.lookup.DataSourceLookup;
@@ -83,6 +83,8 @@ class PersistenceUnitReader {
private static final String META_INF = "META-INF";
private static final String VERSION_1 = "1.0";
private final Log logger = LogFactory.getLog(getClass());
@@ -268,8 +270,14 @@ class PersistenceUnitReader {
// exclude unlisted classes
Element excludeUnlistedClasses = DomUtils.getChildElementByTagName(persistenceUnit, EXCLUDE_UNLISTED_CLASSES);
if (excludeUnlistedClasses != null) {
unitInfo.setExcludeUnlistedClasses(true);
if (excludeUnlistedClasses == null) {
// element is not defined, use default appropriate for version
unitInfo.setExcludeUnlistedClasses(!VERSION_1.equals(version));
}
else {
String excludeText = DomUtils.getTextValue(excludeUnlistedClasses);
unitInfo.setExcludeUnlistedClasses(StringUtils.isEmpty(excludeText) ||
Boolean.valueOf(excludeText));
}
// set JPA 2.0 shared cache mode