mirror of
https://github.com/spring-projects/spring-framework
synced 2026-06-08 17:33:33 +00:00
Adapt to getAllClassNames SPI (post JPA 4.0 M1)
See gh-35705
This commit is contained in:
+11
-1
@@ -18,6 +18,7 @@ package org.springframework.orm.jpa.persistenceunit;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
@@ -72,6 +73,15 @@ public final class PersistenceManagedTypesScanner {
|
||||
entityTypeFilters.add(new AnnotationTypeFilter(Embeddable.class, false));
|
||||
entityTypeFilters.add(new AnnotationTypeFilter(MappedSuperclass.class, false));
|
||||
entityTypeFilters.add(new AnnotationTypeFilter(Converter.class, false));
|
||||
try {
|
||||
@SuppressWarnings("unchecked")
|
||||
Class<? extends Annotation> discoverable = (Class<? extends Annotation>) ClassUtils.forName(
|
||||
"jakarta.persistence.spi.Discoverable", PersistenceManagedTypesScanner.class.getClassLoader());
|
||||
entityTypeFilters.add(new AnnotationTypeFilter(discoverable, true));
|
||||
}
|
||||
catch (ClassNotFoundException ex) {
|
||||
// JPA 4.0 API not present - simply skip.
|
||||
}
|
||||
}
|
||||
|
||||
private final ResourcePatternResolver resourcePatternResolver;
|
||||
@@ -147,7 +157,7 @@ public final class PersistenceManagedTypesScanner {
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (className.endsWith(PACKAGE_INFO_SUFFIX)) {
|
||||
if (className.endsWith(PACKAGE_INFO_SUFFIX)) {
|
||||
scanResult.managedPackages.add(className.substring(0,
|
||||
className.length() - PACKAGE_INFO_SUFFIX.length()));
|
||||
}
|
||||
|
||||
+5
-8
@@ -262,16 +262,13 @@ public class SpringPersistenceUnitInfo extends MutablePersistenceUnitInfo {
|
||||
// Fast path for SmartPersistenceUnitInfo JTA check
|
||||
return (getTransactionType() == PersistenceUnitTransactionType.JTA);
|
||||
}
|
||||
else if (method.getName().equals("getAllManagedClassNames")) {
|
||||
// JPA 4.0 letting the container perform the scanning ->
|
||||
// with Spring, only makes sense with typical default persistence unit.
|
||||
if (excludeUnlistedClasses() && getMappingFileNames().isEmpty()) {
|
||||
List<String> mergedClassesAndPackages = new ArrayList<>(getManagedClassNames());
|
||||
mergedClassesAndPackages.addAll(getManagedPackages());
|
||||
return mergedClassesAndPackages;
|
||||
else if (method.getName().equals("getAllClassNames")) {
|
||||
// JPA 4.0 letting the container perform the scanning
|
||||
if (excludeUnlistedClasses()) {
|
||||
return getManagedClassNames(); // typically coming from Spring default persistence unit
|
||||
}
|
||||
throw new UnsupportedOperationException(
|
||||
"JPA 4.0 getAllManagedClassNames only supported with exclude-unlisted-classes and no orm.xml");
|
||||
"JPA 4.0 getAllClassNames only supported with exclude-unlisted-classes");
|
||||
}
|
||||
|
||||
// Regular methods to be delegated to SpringPersistenceUnitInfo
|
||||
|
||||
Reference in New Issue
Block a user