From a97a7620861edadd5c05683c37c3f515a6aa65ca Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Fri, 9 Feb 2018 12:00:47 +0100 Subject: [PATCH] Only set mapping resources when present This commit sets a mapping resources list only when there is at least an element in it. This allows the default fallback of finding an "orm.xml" file to kick in when no customization has been applied. Closes gh-11964 --- .../boot/autoconfigure/orm/jpa/JpaBaseConfiguration.java | 7 +++++-- .../boot/orm/jpa/EntityManagerFactoryBuilder.java | 5 +++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/JpaBaseConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/JpaBaseConfiguration.java index 81be8a39f7..475dcfc992 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/JpaBaseConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/JpaBaseConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 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. @@ -54,6 +54,7 @@ import org.springframework.orm.jpa.support.OpenEntityManagerInViewInterceptor; import org.springframework.orm.jpa.vendor.AbstractJpaVendorAdapter; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.jta.JtaTransactionManager; +import org.springframework.util.ObjectUtils; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @@ -164,7 +165,9 @@ public abstract class JpaBaseConfiguration implements BeanFactoryAware { private String[] getMappingResources() { List mappingResources = this.properties.getMappingResources(); - return mappingResources.toArray(new String[mappingResources.size()]); + return (!ObjectUtils.isEmpty(mappingResources) + ? mappingResources.toArray(new String[mappingResources.size()]) + : null); } /** diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/orm/jpa/EntityManagerFactoryBuilder.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/orm/jpa/EntityManagerFactoryBuilder.java index cea5edc7ec..078368015f 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/orm/jpa/EntityManagerFactoryBuilder.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/orm/jpa/EntityManagerFactoryBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 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. @@ -29,6 +29,7 @@ import org.springframework.orm.jpa.JpaVendorAdapter; import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; import org.springframework.orm.jpa.persistenceunit.PersistenceUnitManager; import org.springframework.util.ClassUtils; +import org.springframework.util.ObjectUtils; /** * Convenient builder for JPA EntityManagerFactory instances. Collects common @@ -220,7 +221,7 @@ public class EntityManagerFactoryBuilder { entityManagerFactoryBean.getJpaPropertyMap() .putAll(EntityManagerFactoryBuilder.this.jpaProperties); entityManagerFactoryBean.getJpaPropertyMap().putAll(this.properties); - if (this.mappingResources != null) { + if (!ObjectUtils.isEmpty(this.mappingResources)) { entityManagerFactoryBean.setMappingResources(this.mappingResources); } URL rootLocation = EntityManagerFactoryBuilder.this.persistenceUnitRootLocation;