diff --git a/src/main/java/org/springframework/data/jpa/repository/query/QueryUtils.java b/src/main/java/org/springframework/data/jpa/repository/query/QueryUtils.java index 025bc5952..55fd9a8f0 100644 --- a/src/main/java/org/springframework/data/jpa/repository/query/QueryUtils.java +++ b/src/main/java/org/springframework/data/jpa/repository/query/QueryUtils.java @@ -509,6 +509,7 @@ public abstract class QueryUtils { Assert.notNull(cb, "CriteriaBuilder must not be null!"); List orders = new ArrayList<>(); + for (org.springframework.data.domain.Sort.Order order : sort) { orders.add(toJpaOrder(order, from, cb)); } @@ -653,7 +654,7 @@ public abstract class QueryUtils { boolean sameName = join.getAttribute().getName().equals(attribute); - if (sameName && join.getJoinType() == JoinType.LEFT) { + if (sameName && join.getJoinType().equals(JoinType.LEFT)) { return join; } } @@ -670,11 +671,11 @@ public abstract class QueryUtils { */ private static boolean isAlreadyFetched(From from, String attribute) { - for (Fetch f : from.getFetches()) { + for (Fetch fetch : from.getFetches()) { - boolean sameName = f.getAttribute().getName().equals(attribute); + boolean sameName = fetch.getAttribute().getName().equals(attribute); - if (sameName && f.getJoinType().equals(JoinType.LEFT)) { + if (sameName && fetch.getJoinType().equals(JoinType.LEFT)) { return true; } } diff --git a/src/main/java/org/springframework/data/jpa/support/ClasspathScanningPersistenceUnitPostProcessor.java b/src/main/java/org/springframework/data/jpa/support/ClasspathScanningPersistenceUnitPostProcessor.java index 0136f6d6c..e87f0ce39 100644 --- a/src/main/java/org/springframework/data/jpa/support/ClasspathScanningPersistenceUnitPostProcessor.java +++ b/src/main/java/org/springframework/data/jpa/support/ClasspathScanningPersistenceUnitPostProcessor.java @@ -74,6 +74,7 @@ public class ClasspathScanningPersistenceUnitPostProcessor public ClasspathScanningPersistenceUnitPostProcessor(String basePackage) { Assert.hasText(basePackage, "Base package must not be null!"); + this.basePackage = basePackage; } @@ -86,6 +87,7 @@ public class ClasspathScanningPersistenceUnitPostProcessor public void setMappingFileNamePattern(String mappingFilePattern) { Assert.hasText(mappingFilePattern, "Mapping file pattern must not be null or empty!"); + this.mappingFileNamePattern = mappingFilePattern; } @@ -96,6 +98,7 @@ public class ClasspathScanningPersistenceUnitPostProcessor public void setResourceLoader(ResourceLoader resourceLoader) { Assert.notNull(resourceLoader, "ResourceLoader must not be null!"); + this.mappingFileResolver = ResourcePatternUtils.getResourcePatternResolver(resourceLoader); this.resourceLoader = resourceLoader; } @@ -108,6 +111,7 @@ public class ClasspathScanningPersistenceUnitPostProcessor public void setEnvironment(Environment environment) { Assert.notNull(environment, "Environment must not be null!"); + this.environment = environment; } @@ -134,7 +138,9 @@ public class ClasspathScanningPersistenceUnitPostProcessor } for (String location : scanForMappingFileLocations()) { + LOG.debug("Registering classpath-scanned entity mapping file {} in persistence unit info!", location); + pui.addMappingFileName(location); } } @@ -172,11 +178,15 @@ public class ClasspathScanningPersistenceUnitPostProcessor } Set mappingFileUris = new HashSet<>(); + for (Resource resource : scannedResources) { + try { + String resourcePath = getResourcePath(resource.getURI()); String resourcePathInClasspath = resourcePath.substring(resourcePath.indexOf(basePackagePathComponent)); mappingFileUris.add(resourcePathInClasspath); + } catch (IOException e) { throw new IllegalStateException(String.format("Couldn't get URI for %s!", resource.toString()), e); } @@ -197,8 +207,11 @@ public class ClasspathScanningPersistenceUnitPostProcessor if (uri.isOpaque()) { // e.g. jar:file:/foo/lib/somelib.jar!/com/acme/orm.xml String rawPath = uri.toString(); + if (rawPath != null) { + int exclamationMarkIndex = rawPath.lastIndexOf('!'); + if (exclamationMarkIndex > -1) { // /com/acme/orm.xml