Create spring-boot-jpa module

See gh-46095
This commit is contained in:
Stéphane Nicoll
2025-07-01 11:55:13 +01:00
committed by Andy Wilkinson
parent 3140c4d924
commit 1b816bd22d
89 changed files with 368 additions and 282 deletions
+1
View File
@@ -75,6 +75,7 @@ include "spring-boot-project:spring-boot-jackson"
include "spring-boot-project:spring-boot-jdbc"
include "spring-boot-project:spring-boot-jetty"
include "spring-boot-project:spring-boot-jms"
include "spring-boot-project:spring-boot-jpa"
include "spring-boot-project:spring-boot-jsonb"
include "spring-boot-project:spring-boot-kafka"
include "spring-boot-project:spring-boot-liquibase"
@@ -41,6 +41,7 @@ dependencies {
optional(project(":spring-boot-project:spring-boot-jackson"))
optional(project(":spring-boot-project:spring-boot-jdbc"))
optional(project(":spring-boot-project:spring-boot-jetty"))
optional(project(":spring-boot-project:spring-boot-jpa"))
optional(project(":spring-boot-project:spring-boot-jsonb"))
optional(project(":spring-boot-project:spring-boot-kafka"))
optional(project(":spring-boot-project:spring-boot-liquibase"))
@@ -34,7 +34,6 @@ import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.util.StringUtils;
/**
@@ -45,8 +44,8 @@ import org.springframework.util.StringUtils;
* @author Stephane Nicoll
* @since 2.1.0
*/
@AutoConfiguration(after = { MetricsAutoConfiguration.class, HibernateJpaAutoConfiguration.class,
SimpleMetricsExportAutoConfiguration.class })
@AutoConfiguration(after = { MetricsAutoConfiguration.class, SimpleMetricsExportAutoConfiguration.class },
afterName = "org.springframework.boot.jpa.autoconfigure.hibernate.HibernateJpaAutoConfiguration")
@ConditionalOnClass({ EntityManagerFactory.class, SessionFactory.class, HibernateMetrics.class, MeterRegistry.class })
@ConditionalOnBean({ EntityManagerFactory.class, MeterRegistry.class })
public class HibernateMetricsAutoConfiguration implements SmartInitializingSingleton {
@@ -27,8 +27,8 @@ import org.springframework.boot.autoconfigure.AutoConfigurationPackage;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.boot.jdbc.autoconfigure.EmbeddedDataSourceConfiguration;
import org.springframework.boot.jpa.autoconfigure.hibernate.HibernateJpaAutoConfiguration;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -34,11 +34,11 @@ import org.mockito.ArgumentMatchers;
import org.springframework.boot.actuate.autoconfigure.metrics.test.MetricsRun;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.orm.jpa.EntityManagerFactoryBuilderCustomizer;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.boot.jdbc.autoconfigure.DataSourceAutoConfiguration;
import org.springframework.boot.jdbc.autoconfigure.DataSourceInitializationAutoConfiguration;
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
import org.springframework.boot.jpa.EntityManagerFactoryBuilder;
import org.springframework.boot.jpa.autoconfigure.EntityManagerFactoryBuilderCustomizer;
import org.springframework.boot.jpa.autoconfigure.hibernate.HibernateJpaAutoConfiguration;
import org.springframework.boot.test.context.FilteredClassLoader;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.boot.testsupport.classpath.resources.WithResource;
@@ -6,11 +6,6 @@ org.springframework.boot.rsocket.context.RSocketPortInfoApplicationContextInitia
org.springframework.boot.env.EnvironmentPostProcessor=\
org.springframework.boot.reactor.ReactorEnvironmentPostProcessor
# Database Initializer Detectors
org.springframework.boot.sql.init.dependency.DatabaseInitializerDetector=\
org.springframework.boot.orm.jpa.JpaDatabaseInitializerDetector
# Depends On Database Initialization Detectors
org.springframework.boot.sql.init.dependency.DependsOnDatabaseInitializationDetector=\
org.springframework.boot.jooq.JooqDependsOnDatabaseInitializationDetector,\
org.springframework.boot.orm.jpa.JpaDependsOnDatabaseInitializationDetector
org.springframework.boot.jooq.JooqDependsOnDatabaseInitializationDetector
@@ -64,6 +64,7 @@ dependencies {
optional(project(":spring-boot-project:spring-boot-flyway"))
optional(project(":spring-boot-project:spring-boot-jackson"))
optional(project(":spring-boot-project:spring-boot-jdbc"))
optional(project(":spring-boot-project:spring-boot-jpa"))
optional(project(":spring-boot-project:spring-boot-jsonb"))
optional(project(":spring-boot-project:spring-boot-liquibase"))
optional(project(":spring-boot-project:spring-boot-r2dbc"))
@@ -35,7 +35,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBooleanProperty;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.boot.autoconfigure.sql.init.OnDatabaseInitializationCondition;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.sql.init.dependency.DatabaseInitializationDependencyConfigurer;
@@ -70,7 +69,8 @@ import org.springframework.util.StringUtils;
* @author Yanming Zhou
* @since 1.0.0
*/
@AutoConfiguration(after = { HibernateJpaAutoConfiguration.class, TransactionAutoConfiguration.class })
@AutoConfiguration(after = TransactionAutoConfiguration.class,
afterName = "org.springframework.boot.jpa.autoconfigure.hibernate.HibernateJpaAutoConfiguration")
@ConditionalOnClass({ JobLauncher.class, DataSource.class, DatabasePopulator.class })
@ConditionalOnBean({ DataSource.class, PlatformTransactionManager.class })
@ConditionalOnMissingBean(value = DefaultBatchConfiguration.class, annotation = EnableBatchProcessing.class)
@@ -21,20 +21,20 @@ import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration.CacheConfigurationImportSelector;
import org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration.CacheManagerEntityManagerFactoryDependsOnPostProcessor;
import org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration.CacheManagerEntityManagerFactoryDependsOnConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.data.couchbase.CouchbaseDataAutoConfiguration;
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
import org.springframework.boot.autoconfigure.hazelcast.HazelcastAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.EntityManagerFactoryDependsOnPostProcessor;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.jpa.autoconfigure.EntityManagerFactoryDependsOnPostProcessor;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.interceptor.CacheAspectSupport;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.ImportSelector;
import org.springframework.core.type.AnnotationMetadata;
@@ -53,13 +53,15 @@ import org.springframework.util.Assert;
* @since 1.3.0
* @see EnableCaching
*/
@AutoConfiguration(after = { CouchbaseDataAutoConfiguration.class, HazelcastAutoConfiguration.class,
HibernateJpaAutoConfiguration.class, RedisAutoConfiguration.class })
@AutoConfiguration(
after = { CouchbaseDataAutoConfiguration.class, HazelcastAutoConfiguration.class,
RedisAutoConfiguration.class },
afterName = "org.springframework.boot.jpa.autoconfigure.hibernate.HibernateJpaAutoConfiguration")
@ConditionalOnClass(CacheManager.class)
@ConditionalOnBean(CacheAspectSupport.class)
@ConditionalOnMissingBean(value = CacheManager.class, name = "cacheResolver")
@EnableConfigurationProperties(CacheProperties.class)
@Import({ CacheConfigurationImportSelector.class, CacheManagerEntityManagerFactoryDependsOnPostProcessor.class })
@Import({ CacheConfigurationImportSelector.class, CacheManagerEntityManagerFactoryDependsOnConfiguration.class })
public class CacheAutoConfiguration {
@Bean
@@ -74,8 +76,15 @@ public class CacheAutoConfiguration {
return new CacheManagerValidator(cacheProperties, cacheManager);
}
@ConditionalOnClass(LocalContainerEntityManagerFactoryBean.class)
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass({ EntityManagerFactoryDependsOnPostProcessor.class,
LocalContainerEntityManagerFactoryBean.class })
@ConditionalOnBean(AbstractEntityManagerFactoryBean.class)
@Import(CacheManagerEntityManagerFactoryDependsOnPostProcessor.class)
static class CacheManagerEntityManagerFactoryDependsOnConfiguration {
}
static class CacheManagerEntityManagerFactoryDependsOnPostProcessor
extends EntityManagerFactoryDependsOnPostProcessor {
@@ -29,9 +29,9 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration.JpaRepositoriesImportSelector;
import org.springframework.boot.autoconfigure.orm.jpa.EntityManagerFactoryBuilderCustomizer;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration;
import org.springframework.boot.jpa.autoconfigure.EntityManagerFactoryBuilderCustomizer;
import org.springframework.boot.jpa.autoconfigure.hibernate.HibernateJpaAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Import;
@@ -23,10 +23,10 @@ import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.AllNestedConditions;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.hazelcast.HazelcastJpaDependencyAutoConfiguration.HazelcastInstanceEntityManagerFactoryDependsOnPostProcessor;
import org.springframework.boot.autoconfigure.orm.jpa.EntityManagerFactoryDependsOnPostProcessor;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.boot.autoconfigure.hazelcast.HazelcastJpaDependencyAutoConfiguration.HazelcastInstanceEntityManagerFactoryDependsOnConfiguration;
import org.springframework.boot.jpa.autoconfigure.EntityManagerFactoryDependsOnPostProcessor;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.orm.jpa.AbstractEntityManagerFactoryBean;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
@@ -38,12 +38,20 @@ import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
* @author Stephane Nicoll
* @since 1.3.2
*/
@AutoConfiguration(after = { HazelcastAutoConfiguration.class, HibernateJpaAutoConfiguration.class })
@AutoConfiguration(after = HazelcastAutoConfiguration.class,
afterName = "org.springframework.boot.jpa.autoconfigure.hibernate.HibernateJpaAutoConfiguration")
@ConditionalOnClass({ HazelcastInstance.class, LocalContainerEntityManagerFactoryBean.class })
@Import(HazelcastInstanceEntityManagerFactoryDependsOnPostProcessor.class)
@Import(HazelcastInstanceEntityManagerFactoryDependsOnConfiguration.class)
public class HazelcastJpaDependencyAutoConfiguration {
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(EntityManagerFactoryDependsOnPostProcessor.class)
@Conditional(OnHazelcastAndJpaCondition.class)
@Import(HazelcastInstanceEntityManagerFactoryDependsOnPostProcessor.class)
static class HazelcastInstanceEntityManagerFactoryDependsOnConfiguration {
}
static class HazelcastInstanceEntityManagerFactoryDependsOnPostProcessor
extends EntityManagerFactoryDependsOnPostProcessor {
@@ -33,7 +33,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.boot.autoconfigure.sql.init.OnDatabaseInitializationCondition;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.jdbc.autoconfigure.DataSourceAutoConfiguration;
@@ -55,7 +54,8 @@ import org.springframework.transaction.PlatformTransactionManager;
* @author Stephane Nicoll
* @since 2.0.0
*/
@AutoConfiguration(after = { DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class })
@AutoConfiguration(after = DataSourceAutoConfiguration.class,
afterName = "org.springframework.boot.jpa.autoconfigure.hibernate.HibernateJpaAutoConfiguration")
@ConditionalOnClass({ Scheduler.class, SchedulerFactoryBean.class, PlatformTransactionManager.class })
@EnableConfigurationProperties(QuartzProperties.class)
public class QuartzAutoConfiguration {
@@ -783,19 +783,6 @@
"reason": "The new InfluxDb Java client provides Spring Boot integration."
}
},
{
"name": "spring.jpa.hibernate.use-new-id-generator-mappings",
"type": "java.lang.Boolean",
"description": "Whether to use Hibernate's newer IdentifierGenerator for AUTO, TABLE and SEQUENCE. This is actually a shortcut for the \"hibernate.id.new_generator_mappings\" property. When not specified will default to \"true\".",
"deprecation": {
"level": "error",
"reason": "Hibernate no longer supports disabling the use of new ID generator mappings."
}
},
{
"name": "spring.jpa.open-in-view",
"defaultValue": true
},
{
"name": "spring.jta.enabled",
"type": "java.lang.Boolean",
@@ -1809,65 +1796,6 @@
}
]
},
{
"name": "spring.jpa.hibernate.ddl-auto",
"values": [
{
"value": "create",
"description": "Create the schema and destroy previous data."
},
{
"value": "create-drop",
"description": "Create and then destroy the schema at the end of the session."
},
{
"value": "create-only",
"description": "Create the schema."
},
{
"value": "drop",
"description": "Drop the schema."
},
{
"value": "none",
"description": "Disable DDL handling."
},
{
"value": "truncate",
"description": "Truncate the tables in the schema."
},
{
"value": "update",
"description": "Update the schema if necessary."
},
{
"value": "validate",
"description": "Validate the schema, make no changes to the database."
}
]
},
{
"name": "spring.jpa.hibernate.naming.implicit-strategy",
"providers": [
{
"name": "class-reference",
"parameters": {
"target": "org.hibernate.boot.model.naming.ImplicitNamingStrategy"
}
}
]
},
{
"name": "spring.jpa.hibernate.naming.physical-strategy",
"providers": [
{
"name": "class-reference",
"parameters": {
"target": "org.hibernate.boot.model.naming.PhysicalNamingStrategy"
}
}
]
},
{
"name": "spring.kafka.consumer.auto-offset-reset",
"values": [
@@ -65,7 +65,6 @@ org.springframework.boot.autoconfigure.mongo.MongoReactiveAutoConfiguration
org.springframework.boot.autoconfigure.mustache.MustacheAutoConfiguration
org.springframework.boot.autoconfigure.neo4j.Neo4jAutoConfiguration
org.springframework.boot.autoconfigure.netty.NettyAutoConfiguration
org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration
org.springframework.boot.autoconfigure.quartz.QuartzAutoConfiguration
org.springframework.boot.autoconfigure.reactor.ReactorAutoConfiguration
org.springframework.boot.autoconfigure.rsocket.RSocketMessagingAutoConfiguration
@@ -60,13 +60,13 @@ import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.TestAutoConfigurationPackage;
import org.springframework.boot.autoconfigure.batch.BatchAutoConfiguration.SpringBootBatchConfiguration;
import org.springframework.boot.autoconfigure.batch.domain.City;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.boot.flyway.autoconfigure.FlywayAutoConfiguration;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.boot.jdbc.autoconfigure.DataSourceAutoConfiguration;
import org.springframework.boot.jdbc.autoconfigure.DataSourceTransactionManagerAutoConfiguration;
import org.springframework.boot.jdbc.autoconfigure.EmbeddedDataSourceConfiguration;
import org.springframework.boot.jdbc.init.DataSourceScriptDatabaseInitializer;
import org.springframework.boot.jpa.autoconfigure.hibernate.HibernateJpaAutoConfiguration;
import org.springframework.boot.liquibase.autoconfigure.LiquibaseAutoConfiguration;
import org.springframework.boot.sql.init.DatabaseInitializationMode;
import org.springframework.boot.sql.init.DatabaseInitializationSettings;
@@ -23,8 +23,8 @@ import jakarta.persistence.EntityManagerFactory;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.boot.jdbc.autoconfigure.EmbeddedDataSourceConfiguration;
import org.springframework.boot.jpa.autoconfigure.hibernate.HibernateJpaAutoConfiguration;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
@@ -28,10 +28,10 @@ import org.springframework.boot.autoconfigure.data.alt.mongo.CityMongoDbReposito
import org.springframework.boot.autoconfigure.data.jpa.city.City;
import org.springframework.boot.autoconfigure.data.jpa.city.CityRepository;
import org.springframework.boot.autoconfigure.data.jpa.country.Country;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration;
import org.springframework.boot.autoconfigure.task.TaskSchedulingAutoConfiguration;
import org.springframework.boot.jdbc.autoconfigure.EmbeddedDataSourceConfiguration;
import org.springframework.boot.jpa.autoconfigure.hibernate.HibernateJpaAutoConfiguration;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan.Filter;
@@ -30,8 +30,8 @@ import org.springframework.boot.autoconfigure.data.mongo.country.Country;
import org.springframework.boot.autoconfigure.data.mongo.country.CountryRepository;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.boot.jdbc.autoconfigure.DataSourceAutoConfiguration;
import org.springframework.boot.jpa.autoconfigure.hibernate.HibernateJpaAutoConfiguration;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Configuration;
@@ -32,8 +32,8 @@ import org.springframework.boot.autoconfigure.data.neo4j.country.Country;
import org.springframework.boot.autoconfigure.data.neo4j.country.CountryRepository;
import org.springframework.boot.autoconfigure.data.neo4j.empty.EmptyMarker;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.boot.jdbc.autoconfigure.DataSourceAutoConfiguration;
import org.springframework.boot.jpa.autoconfigure.hibernate.HibernateJpaAutoConfiguration;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
@@ -26,9 +26,9 @@ import org.springframework.boot.autoconfigure.TestAutoConfigurationPackage;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration;
import org.springframework.boot.autoconfigure.data.jpa.city.City;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.boot.jackson.autoconfigure.JacksonAutoConfiguration;
import org.springframework.boot.jdbc.autoconfigure.EmbeddedDataSourceConfiguration;
import org.springframework.boot.jpa.autoconfigure.hibernate.HibernateJpaAutoConfiguration;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebApplicationContext;
import org.springframework.context.annotation.Bean;
@@ -23,8 +23,8 @@ import org.springframework.boot.autoconfigure.TestAutoConfigurationPackage;
import org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration;
import org.springframework.boot.autoconfigure.data.jpa.city.City;
import org.springframework.boot.autoconfigure.data.jpa.city.CityRepository;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.boot.jdbc.autoconfigure.DataSourceAutoConfiguration;
import org.springframework.boot.jpa.autoconfigure.hibernate.HibernateJpaAutoConfiguration;
import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.geo.Distance;
@@ -27,9 +27,9 @@ import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.hazelcast.HazelcastJpaDependencyAutoConfiguration.HazelcastInstanceEntityManagerFactoryDependsOnPostProcessor;
import org.springframework.boot.autoconfigure.orm.jpa.EntityManagerFactoryDependsOnPostProcessor;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.boot.jdbc.autoconfigure.DataSourceAutoConfiguration;
import org.springframework.boot.jpa.autoconfigure.EntityManagerFactoryDependsOnPostProcessor;
import org.springframework.boot.jpa.autoconfigure.hibernate.HibernateJpaAutoConfiguration;
import org.springframework.boot.test.context.assertj.AssertableApplicationContext;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.context.annotation.Bean;
@@ -19,10 +19,10 @@ package org.springframework.boot.autoconfigure.security.jpa;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
import org.springframework.boot.jdbc.autoconfigure.DataSourceAutoConfiguration;
import org.springframework.boot.jdbc.autoconfigure.EmbeddedDataSourceConfiguration;
import org.springframework.boot.jpa.autoconfigure.hibernate.HibernateJpaAutoConfiguration;
import org.springframework.boot.test.context.SpringBootContextLoader;
import org.springframework.context.annotation.Import;
import org.springframework.test.annotation.DirtiesContext;
@@ -30,7 +30,6 @@ import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.TestAutoConfigurationPackage;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.boot.autoconfigure.security.jpa.City;
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration;
import org.springframework.boot.context.properties.ConfigurationProperties;
@@ -38,6 +37,7 @@ import org.springframework.boot.context.properties.ConfigurationPropertiesBindin
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.convert.ApplicationConversionService;
import org.springframework.boot.jdbc.autoconfigure.DataSourceAutoConfiguration;
import org.springframework.boot.jpa.autoconfigure.hibernate.HibernateJpaAutoConfiguration;
import org.springframework.boot.test.context.FilteredClassLoader;
import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
import org.springframework.boot.testsupport.classpath.resources.WithResource;
@@ -29,6 +29,7 @@ dependencies {
api(project(":spring-boot-project:spring-boot"))
optional("com.github.ben-manes.caffeine:caffeine")
optional("jakarta.persistence:jakarta.persistence-api")
optional("jakarta.servlet:jakarta.servlet-api")
optional("org.springframework:spring-web")
@@ -27,23 +27,8 @@ import org.springframework.core.annotation.AliasFor;
/**
* Configures the base packages used by auto-configuration when scanning for entity
* classes.
* <p>
* Using {@code @EntityScan} will cause auto-configuration to:
* <ul>
* <li>Set the
* {@link org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean#setPackagesToScan(String...)
* packages scanned} for JPA entities.</li>
* <li>Set the
* {@link org.springframework.data.mapping.context.AbstractMappingContext#setInitialEntitySet(java.util.Set)
* initial entity set} used with Spring Data
* {@link org.springframework.data.mongodb.core.mapping.MongoMappingContext MongoDB},
* {@link org.springframework.data.neo4j.core.mapping.Neo4jMappingContext Neo4j},
* {@link org.springframework.data.cassandra.core.mapping.CassandraMappingContext
* Cassandra} and
* {@link org.springframework.data.couchbase.core.mapping.CouchbaseMappingContext
* Couchbase} mapping contexts.</li>
* </ul>
* classes. Refer to the documentation of the data technology you are using for more
* details.
* <p>
* One of {@link #basePackageClasses()}, {@link #basePackages()} or its alias
* {@link #value()} may be specified to define specific packages to scan. If specific
@@ -51,7 +36,7 @@ import org.springframework.core.annotation.AliasFor;
* annotation.
*
* @author Phillip Webb
* @since 1.4.0
* @since 4.0.0
* @see EntityScanPackages
*/
@Target(ElementType.TYPE)
@@ -43,7 +43,7 @@ import org.springframework.util.StringUtils;
* (e.g. by JPA auto-configuration).
*
* @author Phillip Webb
* @since 1.4.0
* @since 4.0.0
* @see EntityScan
* @see EntityScanner
*/
@@ -36,7 +36,7 @@ import org.springframework.util.StringUtils;
* specified packages.
*
* @author Phillip Webb
* @since 1.4.0
* @since 4.0.0
*/
public class EntityScanner {
@@ -2004,6 +2004,7 @@ bom {
"spring-boot-jdbc",
"spring-boot-jetty",
"spring-boot-jms",
"spring-boot-jpa",
"spring-boot-jsonb",
"spring-boot-kafka",
"spring-boot-liquibase",
@@ -53,6 +53,7 @@ dependencies {
intTestRuntimeOnly("org.springframework:spring-web")
optional(project(":spring-boot-project:spring-boot-jdbc"))
optional(project(":spring-boot-project:spring-boot-jpa"))
optional(project(":spring-boot-project:spring-boot-r2dbc"))
optional("io.projectreactor:reactor-core")
optional("io.r2dbc:r2dbc-spi")
@@ -36,14 +36,15 @@ import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
import org.springframework.boot.autoconfigure.orm.jpa.EntityManagerFactoryDependsOnPostProcessor;
import org.springframework.boot.devtools.autoconfigure.DevToolsDataSourceAutoConfiguration.DatabaseShutdownExecutorEntityManagerFactoryDependsOnPostProcessor;
import org.springframework.boot.devtools.autoconfigure.DevToolsDataSourceAutoConfiguration.DatabaseShutdownExecutorEntityManagerFactoryDependsOnConfiguration;
import org.springframework.boot.devtools.autoconfigure.DevToolsDataSourceAutoConfiguration.DevToolsDataSourceCondition;
import org.springframework.boot.jdbc.autoconfigure.DataSourceAutoConfiguration;
import org.springframework.boot.jdbc.autoconfigure.DataSourceProperties;
import org.springframework.boot.jpa.autoconfigure.EntityManagerFactoryDependsOnPostProcessor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ConfigurationCondition;
import org.springframework.context.annotation.Import;
import org.springframework.core.type.AnnotatedTypeMetadata;
@@ -61,7 +62,7 @@ import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
@ConditionalOnEnabledDevTools
@Conditional(DevToolsDataSourceCondition.class)
@AutoConfiguration(afterName = "org.springframework.boot.jdbc.autoconfigure.DataSourceAutoConfiguration")
@Import(DatabaseShutdownExecutorEntityManagerFactoryDependsOnPostProcessor.class)
@Import(DatabaseShutdownExecutorEntityManagerFactoryDependsOnConfiguration.class)
public class DevToolsDataSourceAutoConfiguration {
@Bean
@@ -70,12 +71,19 @@ public class DevToolsDataSourceAutoConfiguration {
return new NonEmbeddedInMemoryDatabaseShutdownExecutor(dataSource, dataSourceProperties);
}
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass({ EntityManagerFactoryDependsOnPostProcessor.class,
LocalContainerEntityManagerFactoryBean.class })
@ConditionalOnBean(AbstractEntityManagerFactoryBean.class)
@Import(DatabaseShutdownExecutorEntityManagerFactoryDependsOnPostProcessor.class)
static class DatabaseShutdownExecutorEntityManagerFactoryDependsOnConfiguration {
}
/**
* Post processor to ensure that {@link jakarta.persistence.EntityManagerFactory}
* beans depend on the {@code inMemoryDatabaseShutdownExecutor} bean.
*/
@ConditionalOnClass(LocalContainerEntityManagerFactoryBean.class)
@ConditionalOnBean(AbstractEntityManagerFactoryBean.class)
static class DatabaseShutdownExecutorEntityManagerFactoryDependsOnPostProcessor
extends EntityManagerFactoryDependsOnPostProcessor {
@@ -89,6 +89,7 @@ dependencies {
autoConfiguration(project(path: ":spring-boot-project:spring-boot-jdbc", configuration: "autoConfigurationMetadata"))
autoConfiguration(project(path: ":spring-boot-project:spring-boot-jetty", configuration: "autoConfigurationMetadata"))
autoConfiguration(project(path: ":spring-boot-project:spring-boot-jms", configuration: "autoConfigurationMetadata"))
autoConfiguration(project(path: ":spring-boot-project:spring-boot-jpa", configuration: "autoConfigurationMetadata"))
autoConfiguration(project(path: ":spring-boot-project:spring-boot-jsonb", configuration: "autoConfigurationMetadata"))
autoConfiguration(project(path: ":spring-boot-project:spring-boot-kafka", configuration: "autoConfigurationMetadata"))
autoConfiguration(project(path: ":spring-boot-project:spring-boot-liquibase", configuration: "autoConfigurationMetadata"))
@@ -117,6 +118,7 @@ dependencies {
configurationProperties(project(path: ":spring-boot-project:spring-boot-freemarker", configuration: "configurationPropertiesMetadata"))
configurationProperties(project(path: ":spring-boot-project:spring-boot-jackson", configuration: "configurationPropertiesMetadata"))
configurationProperties(project(path: ":spring-boot-project:spring-boot-jdbc", configuration: "configurationPropertiesMetadata"))
configurationProperties(project(path: ":spring-boot-project:spring-boot-jpa", configuration: "configurationPropertiesMetadata"))
configurationProperties(project(path: ":spring-boot-project:spring-boot-jetty", configuration: "configurationPropertiesMetadata"))
configurationProperties(project(path: ":spring-boot-project:spring-boot-jms", configuration: "configurationPropertiesMetadata"))
configurationProperties(project(path: ":spring-boot-project:spring-boot-kafka", configuration: "configurationPropertiesMetadata"))
@@ -142,6 +144,7 @@ dependencies {
implementation(project(path: ":spring-boot-project:spring-boot-docker-compose"))
implementation(project(path: ":spring-boot-project:spring-boot-jackson"))
implementation(project(path: ":spring-boot-project:spring-boot-jdbc"))
implementation(project(path: ":spring-boot-project:spring-boot-jpa"))
implementation(project(path: ":spring-boot-project:spring-boot-jms"))
implementation(project(path: ":spring-boot-project:spring-boot-jsonb"))
implementation(project(path: ":spring-boot-project:spring-boot-reactor-netty"))
@@ -229,7 +229,7 @@ For example, if you want to configure Hibernate's batch size you must use `+spri
If you use other forms, such as `batchSize` or `batch-size`, Hibernate will not apply the setting.
====
TIP: If you need to apply advanced customization to Hibernate properties, consider registering a javadoc:org.springframework.boot.autoconfigure.orm.jpa.HibernatePropertiesCustomizer[] bean that will be invoked prior to creating the javadoc:jakarta.persistence.EntityManagerFactory[].
TIP: If you need to apply advanced customization to Hibernate properties, consider registering a javadoc:org.springframework.boot.jpa.autoconfigure.hibernate.HibernatePropertiesCustomizer[] bean that will be invoked prior to creating the javadoc:jakarta.persistence.EntityManagerFactory[].
This takes precedence over anything that is applied by the auto-configuration.
@@ -275,7 +275,7 @@ Hibernate {url-hibernate-userguide}#caching[second-level cache] can be configure
Rather than configuring Hibernate to lookup the cache provider again, it is better to provide the one that is available in the context whenever possible.
To do this with JCache, first make sure that `org.hibernate.orm:hibernate-jcache` is available on the classpath.
Then, add a javadoc:org.springframework.boot.autoconfigure.orm.jpa.HibernatePropertiesCustomizer[] bean as shown in the following example:
Then, add a javadoc:org.springframework.boot.jpa.autoconfigure.hibernate.HibernatePropertiesCustomizer[] bean as shown in the following example:
include-code::MyHibernateSecondLevelCacheConfiguration[]
@@ -290,7 +290,7 @@ For details, see {url-hibernate-userguide}#caching-provider-jcache[the Hibernate
By default, Spring Boot registers a javadoc:org.hibernate.resource.beans.container.spi.BeanContainer[] implementation that uses the javadoc:org.springframework.beans.factory.BeanFactory[] so that converters and entity listeners can use regular dependency injection.
You can disable or tune this behavior by registering a javadoc:org.springframework.boot.autoconfigure.orm.jpa.HibernatePropertiesCustomizer[] that removes or changes the `hibernate.resource.beans.container` property.
You can disable or tune this behavior by registering a javadoc:org.springframework.boot.jpa.autoconfigure.hibernate.HibernatePropertiesCustomizer[] that removes or changes the `hibernate.resource.beans.container` property.
@@ -301,7 +301,7 @@ To take full control of the configuration of the javadoc:jakarta.persistence.Ent
Spring Boot auto-configuration switches off its entity manager in the presence of a bean of that type.
NOTE: When you create a bean for javadoc:org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean[] yourself, any customization that was applied during the creation of the auto-configured javadoc:org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean[] is lost.
Make sure to use the auto-configured javadoc:org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder[] to retain JPA and vendor properties.
Make sure to use the auto-configured javadoc:org.springframework.boot.jpa.EntityManagerFactoryBuilder[] to retain JPA and vendor properties.
This is particularly important if you were relying on `spring.jpa.*` properties for configuring things like the naming strategy or the DDL mode.
@@ -311,7 +311,7 @@ This is particularly important if you were relying on `spring.jpa.*` properties
If you need to use JPA against multiple datasources, you likely need one javadoc:jakarta.persistence.EntityManagerFactory[] per datasource.
The javadoc:org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean[] from Spring ORM allows you to configure an javadoc:jakarta.persistence.EntityManagerFactory[] for your needs.
You can also reuse javadoc:org.springframework.boot.autoconfigure.orm.jpa.JpaProperties[] to bind settings for a second javadoc:jakarta.persistence.EntityManagerFactory[].
You can also reuse javadoc:org.springframework.boot.jpa.autoconfigure.JpaProperties[] to bind settings for a second javadoc:jakarta.persistence.EntityManagerFactory[].
Building upon xref:how-to:data-access.adoc#howto.data-access.configure-two-datasources[the example for configuring a second javadoc:javax.sql.DataSource[]], a second javadoc:jakarta.persistence.EntityManagerFactory[] can be defined as shown in the following example:
include-code::MyAdditionalEntityManagerFactoryConfiguration[]
@@ -390,7 +390,7 @@ If you want to configure a component that JPA uses, then you need to ensure that
When the component is auto-configured, Spring Boot takes care of this for you.
For example, when Flyway is auto-configured, Hibernate is configured to depend on Flyway so that Flyway has a chance to initialize the database before Hibernate tries to use it.
If you are configuring a component yourself, you can use an javadoc:org.springframework.boot.autoconfigure.orm.jpa.EntityManagerFactoryDependsOnPostProcessor[] subclass as a convenient way of setting up the necessary dependencies.
If you are configuring a component yourself, you can use an javadoc:org.springframework.boot.jpa.autoconfigure.EntityManagerFactoryDependsOnPostProcessor[] subclass as a convenient way of setting up the necessary dependencies.
For example, if you use Hibernate Search with Elasticsearch as its index manager, any javadoc:jakarta.persistence.EntityManagerFactory[] beans must be configured to depend on the `elasticsearchClient` bean, as shown in the following example:
include-code::ElasticsearchEntityManagerFactoryDependsOnPostProcessor[]
@@ -252,7 +252,7 @@ include-code::CityRepository[]
Spring Data JPA repositories support three different modes of bootstrapping: default, deferred, and lazy.
To enable deferred or lazy bootstrapping, set the configprop:spring.data.jpa.repositories.bootstrap-mode[] property to `deferred` or `lazy` respectively.
When using deferred or lazy bootstrapping, the auto-configured javadoc:org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder[] will use the context's javadoc:org.springframework.core.task.AsyncTaskExecutor[], if any, as the bootstrap executor.
When using deferred or lazy bootstrapping, the auto-configured javadoc:org.springframework.boot.jpa.EntityManagerFactoryBuilder[] will use the context's javadoc:org.springframework.core.task.AsyncTaskExecutor[], if any, as the bootstrap executor.
If more than one exists, the one named `applicationTaskExecutor` will be used.
[NOTE]
@@ -14,8 +14,8 @@ They use a JSON format with items categorized under either "`groups`" or "`prope
},
{
"name": "spring.jpa.hibernate",
"type": "org.springframework.boot.autoconfigure.orm.jpa.JpaProperties$Hibernate",
"sourceType": "org.springframework.boot.autoconfigure.orm.jpa.JpaProperties",
"type": "org.springframework.boot.jpa.autoconfigure.JpaProperties$Hibernate",
"sourceType": "org.springframework.boot.jpa.autoconfigure.JpaProperties",
"sourceMethod": "getHibernate()"
}
...
@@ -34,7 +34,7 @@ They use a JSON format with items categorized under either "`groups`" or "`prope
"name": "spring.jpa.hibernate.ddl-auto",
"type": "java.lang.String",
"description": "DDL mode. This is actually a shortcut for the \"hibernate.hbm2ddl.auto\" property.",
"sourceType": "org.springframework.boot.autoconfigure.orm.jpa.JpaProperties$Hibernate"
"sourceType": "org.springframework.boot.jpa.autoconfigure.JpaProperties$Hibernate"
}
...
],"hints": [
@@ -18,7 +18,7 @@ package org.springframework.boot.docs.howto.dataaccess.configureacomponentthatis
import jakarta.persistence.EntityManagerFactory;
import org.springframework.boot.autoconfigure.orm.jpa.EntityManagerFactoryDependsOnPostProcessor;
import org.springframework.boot.jpa.autoconfigure.EntityManagerFactoryDependsOnPostProcessor;
import org.springframework.stereotype.Component;
/**
@@ -18,7 +18,7 @@ package org.springframework.boot.docs.howto.dataaccess.configurehibernatesecondl
import org.hibernate.cache.jcache.ConfigSettings;
import org.springframework.boot.autoconfigure.orm.jpa.HibernatePropertiesCustomizer;
import org.springframework.boot.jpa.autoconfigure.hibernate.HibernatePropertiesCustomizer;
import org.springframework.cache.jcache.JCacheCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -23,9 +23,9 @@ import java.util.function.Function;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.orm.jpa.JpaProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
import org.springframework.boot.jpa.EntityManagerFactoryBuilder;
import org.springframework.boot.jpa.autoconfigure.JpaProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.orm.jpa.JpaVendorAdapter;
@@ -16,7 +16,7 @@
package org.springframework.boot.docs.howto.dataaccess.configureacomponentthatisusedbyjpa
import org.springframework.boot.autoconfigure.orm.jpa.EntityManagerFactoryDependsOnPostProcessor
import org.springframework.boot.jpa.autoconfigure.EntityManagerFactoryDependsOnPostProcessor
import org.springframework.stereotype.Component
@Component
@@ -17,7 +17,7 @@
package org.springframework.boot.docs.howto.dataaccess.configurehibernatesecondlevelcaching
import org.hibernate.cache.jcache.ConfigSettings
import org.springframework.boot.autoconfigure.orm.jpa.HibernatePropertiesCustomizer
import org.springframework.boot.jpa.autoconfigure.hibernate.HibernatePropertiesCustomizer
import org.springframework.cache.jcache.JCacheCacheManager
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
@@ -17,9 +17,9 @@
package org.springframework.boot.docs.howto.dataaccess.usemultipleentitymanagers
import org.springframework.beans.factory.annotation.Qualifier
import org.springframework.boot.autoconfigure.orm.jpa.JpaProperties
import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder
import org.springframework.boot.jpa.EntityManagerFactoryBuilder
import org.springframework.boot.jpa.autoconfigure.JpaProperties
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.orm.jpa.JpaVendorAdapter
@@ -67,12 +67,10 @@ import org.springframework.boot.flyway.autoconfigure.FlywayAutoConfiguration.Ora
import org.springframework.boot.flyway.autoconfigure.FlywayAutoConfiguration.PostgresqlFlywayConfigurationCustomizer;
import org.springframework.boot.flyway.autoconfigure.FlywayAutoConfiguration.SqlServerFlywayConfigurationCustomizer;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.boot.jdbc.EmbeddedDatabaseConnection;
import org.springframework.boot.jdbc.SchemaManagement;
import org.springframework.boot.jdbc.autoconfigure.DataSourceProperties;
import org.springframework.boot.jdbc.autoconfigure.EmbeddedDataSourceConfiguration;
import org.springframework.boot.jdbc.autoconfigure.JdbcConnectionDetails;
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
import org.springframework.boot.test.context.FilteredClassLoader;
import org.springframework.boot.test.context.assertj.AssertableApplicationContext;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
@@ -1065,10 +1063,11 @@ class FlywayAutoConfigurationTests {
@Bean
LocalContainerEntityManagerFactoryBean entityManagerFactoryBean(DataSource dataSource) {
return new EntityManagerFactoryBuilder(new HibernateJpaVendorAdapter(), (ds) -> configureJpaProperties(),
null)
.dataSource(dataSource)
.build();
LocalContainerEntityManagerFactoryBean localContainerEntityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
localContainerEntityManagerFactoryBean.setDataSource(dataSource);
localContainerEntityManagerFactoryBean.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
localContainerEntityManagerFactoryBean.setJpaPropertyMap(configureJpaProperties());
return localContainerEntityManagerFactoryBean;
}
}
@@ -1089,50 +1088,11 @@ class FlywayAutoConfigurationTests {
@Bean
LocalContainerEntityManagerFactoryBean entityManagerFactoryBean() {
return new EntityManagerFactoryBuilder(new HibernateJpaVendorAdapter(),
(datasource) -> configureJpaProperties(), null)
.dataSource(this.dataSource)
.build();
}
}
@Configuration(proxyBeanMethods = false)
static class JpaWithMultipleDataSourcesConfiguration {
@Bean
@Primary
DataSource normalDataSource() {
return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseConnection.HSQLDB.getType())
.generateUniqueName(true)
.build();
}
@Bean
@Primary
LocalContainerEntityManagerFactoryBean normalEntityManagerFactory(EntityManagerFactoryBuilder builder,
DataSource normalDataSource) {
Map<String, Object> properties = new HashMap<>();
properties.put("configured", "normal");
properties.put("hibernate.transaction.jta.platform", NoJtaPlatform.INSTANCE);
return builder.dataSource(normalDataSource).properties(properties).build();
}
@Bean
@FlywayDataSource
DataSource flywayDataSource() {
return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseConnection.HSQLDB.getType())
.generateUniqueName(true)
.build();
}
@Bean
LocalContainerEntityManagerFactoryBean flywayEntityManagerFactory(EntityManagerFactoryBuilder builder,
@FlywayDataSource DataSource flywayDataSource) {
Map<String, Object> properties = new HashMap<>();
properties.put("configured", "flyway");
properties.put("hibernate.transaction.jta.platform", NoJtaPlatform.INSTANCE);
return builder.dataSource(flywayDataSource).properties(properties).build();
LocalContainerEntityManagerFactoryBean localContainerEntityManagerFactoryBean = new LocalContainerEntityManagerFactoryBean();
localContainerEntityManagerFactoryBean.setDataSource(this.dataSource);
localContainerEntityManagerFactoryBean.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
localContainerEntityManagerFactoryBean.setJpaPropertyMap(configureJpaProperties());
return localContainerEntityManagerFactoryBean;
}
}
@@ -0,0 +1,58 @@
/*
* Copyright 2012-present 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
plugins {
id "java-library"
id "org.springframework.boot.auto-configuration"
id "org.springframework.boot.configuration-properties"
id "org.springframework.boot.deployed"
id "org.springframework.boot.optional-dependencies"
}
description = "Spring Boot JPA"
dependencies {
api(project(":spring-boot-project:spring-boot-jdbc"))
api(project(":spring-boot-project:spring-boot-tx"))
api("jakarta.persistence:jakarta.persistence-api")
api("org.hibernate.orm:hibernate-core")
api("org.springframework:spring-orm")
optional(project(":spring-boot-project:spring-boot-autoconfigure"))
optional(project(":spring-boot-project:spring-boot-jdbc"))
optional("jakarta.servlet:jakarta.servlet-api")
optional("org.springframework:spring-webmvc")
testImplementation(project(":spring-boot-project:spring-boot-flyway"))
testImplementation(project(":spring-boot-project:spring-boot-liquibase"))
testImplementation(project(":spring-boot-project:spring-boot-test"))
testImplementation(project(":spring-boot-project:spring-boot-tools:spring-boot-test-support"))
testImplementation(testFixtures(project(":spring-boot-project:spring-boot-autoconfigure")))
testImplementation("com.zaxxer:HikariCP")
testImplementation("javax.cache:cache-api")
testImplementation("org.ehcache:ehcache") {
artifact {
classifier = 'jakarta'
}
}
testImplementation("org.hibernate.orm:hibernate-envers")
testImplementation("org.hibernate.orm:hibernate-jcache")
testImplementation("org.springframework:spring-context-support")
testRuntimeOnly("ch.qos.logback:logback-classic")
testRuntimeOnly("com.h2database:h2")
}
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.orm.jpa;
package org.springframework.boot.jpa;
import java.net.URL;
import java.util.HashMap;
@@ -47,7 +47,7 @@ import org.springframework.util.StringUtils;
* @author Dave Syer
* @author Phillip Webb
* @author Stephane Nicoll
* @since 1.3.0
* @since 4.0.0
*/
public class EntityManagerFactoryBuilder {
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.orm.jpa;
package org.springframework.boot.jpa;
import java.util.Collections;
import java.util.HashSet;
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.orm.jpa;
package org.springframework.boot.jpa;
import java.util.Arrays;
import java.util.Collections;
@@ -14,16 +14,16 @@
* limitations under the License.
*/
package org.springframework.boot.autoconfigure.orm.jpa;
package org.springframework.boot.jpa.autoconfigure;
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
import org.springframework.boot.jpa.EntityManagerFactoryBuilder;
/**
* Callback interface that can be used to customize the auto-configured
* {@link EntityManagerFactoryBuilder}.
*
* @author Andy Wilkinson
* @since 2.1.0
* @since 4.0.0
*/
@FunctionalInterface
public interface EntityManagerFactoryBuilderCustomizer {
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.autoconfigure.orm.jpa;
package org.springframework.boot.jpa.autoconfigure;
import jakarta.persistence.EntityManagerFactory;
@@ -32,7 +32,7 @@ import org.springframework.orm.jpa.AbstractEntityManagerFactoryBean;
* @author Phillip Webb
* @author Andy Wilkinson
* @author Andrii Hrytsiuk
* @since 2.5.0
* @since 4.0.0
* @see BeanDefinition#setDependsOn(String[])
*/
public class EntityManagerFactoryDependsOnPostProcessor extends AbstractDependsOnBeanFactoryPostProcessor {
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.autoconfigure.orm.jpa;
package org.springframework.boot.jpa.autoconfigure;
import java.util.HashMap;
import java.util.List;
@@ -38,7 +38,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplicat
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type;
import org.springframework.boot.autoconfigure.domain.EntityScanPackages;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
import org.springframework.boot.jpa.EntityManagerFactoryBuilder;
import org.springframework.boot.transaction.autoconfigure.TransactionManagerCustomizers;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -72,7 +72,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
* @author Kazuki Shimizu
* @author Eddú Meléndez
* @author Yanming Zhou
* @since 1.0.0
* @since 4.0.0
*/
@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties(JpaProperties.class)
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.autoconfigure.orm.jpa;
package org.springframework.boot.jpa.autoconfigure;
import java.util.ArrayList;
import java.util.HashMap;
@@ -32,7 +32,7 @@ import org.springframework.orm.jpa.vendor.Database;
* @author Stephane Nicoll
* @author Eddú Meléndez
* @author Madhura Bhave
* @since 1.1.0
* @since 4.0.0
*/
@ConfigurationProperties("spring.jpa")
public class JpaProperties {
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.autoconfigure.orm.jpa;
package org.springframework.boot.jpa.autoconfigure.hibernate;
import java.util.stream.StreamSupport;
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.autoconfigure.orm.jpa;
package org.springframework.boot.jpa.autoconfigure.hibernate;
import jakarta.persistence.EntityManager;
import org.hibernate.engine.spi.SessionImplementor;
@@ -25,8 +25,10 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.jdbc.autoconfigure.DataSourceAutoConfiguration;
import org.springframework.boot.jdbc.autoconfigure.DataSourceTransactionManagerAutoConfiguration;
import org.springframework.boot.jpa.autoconfigure.JpaProperties;
import org.springframework.boot.transaction.autoconfigure.TransactionAutoConfiguration;
import org.springframework.boot.transaction.autoconfigure.TransactionManagerCustomizationAutoConfiguration;
import org.springframework.boot.transaction.jta.autoconfigure.JtaAutoConfiguration;
import org.springframework.context.annotation.Import;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
@@ -37,11 +39,11 @@ import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
* @author Josh Long
* @author Manuel Doninger
* @author Andy Wilkinson
* @since 1.0.0
* @since 4.0.0
*/
@AutoConfiguration(
after = { DataSourceAutoConfiguration.class, TransactionManagerCustomizationAutoConfiguration.class },
afterName = "org.springframework.boot.autoconfigure.transaction.jta.JtaAutoConfiguration",
after = { DataSourceAutoConfiguration.class, JtaAutoConfiguration.class,
TransactionManagerCustomizationAutoConfiguration.class },
before = { TransactionAutoConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class })
@ConditionalOnClass({ LocalContainerEntityManagerFactoryBean.class, EntityManager.class, SessionImplementor.class })
@EnableConfigurationProperties(JpaProperties.class)
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.autoconfigure.orm.jpa;
package org.springframework.boot.jpa.autoconfigure.hibernate;
import java.util.ArrayList;
import java.util.Arrays;
@@ -43,14 +43,16 @@ import org.springframework.aot.hint.TypeReference;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration.HibernateRuntimeHints;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.jdbc.SchemaManagementProvider;
import org.springframework.boot.jdbc.metadata.CompositeDataSourcePoolMetadataProvider;
import org.springframework.boot.jdbc.metadata.DataSourcePoolMetadata;
import org.springframework.boot.jdbc.metadata.DataSourcePoolMetadataProvider;
import org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy;
import org.springframework.boot.orm.jpa.hibernate.SpringJtaPlatform;
import org.springframework.boot.jpa.autoconfigure.JpaBaseConfiguration;
import org.springframework.boot.jpa.autoconfigure.JpaProperties;
import org.springframework.boot.jpa.autoconfigure.hibernate.HibernateJpaConfiguration.HibernateRuntimeHints;
import org.springframework.boot.jpa.hibernate.SpringImplicitNamingStrategy;
import org.springframework.boot.jpa.hibernate.SpringJtaPlatform;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportRuntimeHints;
import org.springframework.jdbc.support.SQLExceptionTranslator;
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.autoconfigure.orm.jpa;
package org.springframework.boot.jpa.autoconfigure.hibernate;
import java.util.Collection;
import java.util.HashMap;
@@ -27,7 +27,8 @@ import org.hibernate.cfg.PersistenceSettings;
import org.hibernate.cfg.SchemaToolingSettings;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy;
import org.springframework.boot.jpa.autoconfigure.JpaProperties;
import org.springframework.boot.jpa.hibernate.SpringImplicitNamingStrategy;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.ObjectUtils;
@@ -38,7 +39,7 @@ import org.springframework.util.StringUtils;
*
* @author Stephane Nicoll
* @author Chris Bono
* @since 2.1.0
* @since 4.0.0
* @see JpaProperties
*/
@ConfigurationProperties("spring.jpa.hibernate")
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.autoconfigure.orm.jpa;
package org.springframework.boot.jpa.autoconfigure.hibernate;
import java.util.Map;
@@ -23,7 +23,7 @@ import java.util.Map;
* properties before it is used by an auto-configured {@code EntityManagerFactory}.
*
* @author Stephane Nicoll
* @since 2.0.0
* @since 4.0.0
*/
@FunctionalInterface
public interface HibernatePropertiesCustomizer {
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.autoconfigure.orm.jpa;
package org.springframework.boot.jpa.autoconfigure.hibernate;
import java.util.ArrayList;
import java.util.Collection;
@@ -24,7 +24,7 @@ import java.util.function.Supplier;
* Settings to apply when configuring Hibernate.
*
* @author Andy Wilkinson
* @since 2.0.0
* @since 4.0.0
*/
public class HibernateSettings {
@@ -17,4 +17,4 @@
/**
* Auto-configuration for JPA and Spring ORM.
*/
package org.springframework.boot.autoconfigure.orm.jpa;
package org.springframework.boot.jpa.autoconfigure.hibernate;
@@ -0,0 +1,20 @@
/*
* Copyright 2012-present 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Base Auto-configuration for JPA and Spring ORM.
*/
package org.springframework.boot.jpa.autoconfigure;
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.orm.jpa.hibernate;
package org.springframework.boot.jpa.hibernate;
import org.hibernate.boot.model.naming.Identifier;
import org.hibernate.boot.model.naming.ImplicitJoinTableNameSource;
@@ -29,7 +29,7 @@ import org.hibernate.boot.model.naming.ImplicitNamingStrategyJpaCompliantImpl;
* <code>{owning_physical_table_name}_{association_owning_property_name}</code>.
*
* @author Andy Wilkinson
* @since 1.4.0
* @since 4.0.0
*/
public class SpringImplicitNamingStrategy extends ImplicitNamingStrategyJpaCompliantImpl {
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.orm.jpa.hibernate;
package org.springframework.boot.jpa.hibernate;
import jakarta.transaction.TransactionManager;
import jakarta.transaction.UserTransaction;
@@ -30,7 +30,7 @@ import org.springframework.util.Assert;
*
* @author Josh Long
* @author Phillip Webb
* @since 1.2.0
* @since 4.0.0
*/
public class SpringJtaPlatform extends AbstractJtaPlatform {
@@ -17,4 +17,4 @@
/**
* Hibernate Support classes.
*/
package org.springframework.boot.orm.jpa.hibernate;
package org.springframework.boot.jpa.hibernate;
@@ -17,4 +17,4 @@
/**
* JPA Support classes.
*/
package org.springframework.boot.orm.jpa;
package org.springframework.boot.jpa;
@@ -0,0 +1,79 @@
{
"groups": [],
"properties": [
{
"name": "spring.jpa.hibernate.use-new-id-generator-mappings",
"type": "java.lang.Boolean",
"description": "Whether to use Hibernate's newer IdentifierGenerator for AUTO, TABLE and SEQUENCE. This is actually a shortcut for the \"hibernate.id.new_generator_mappings\" property. When not specified will default to \"true\".",
"deprecation": {
"level": "error",
"reason": "Hibernate no longer supports disabling the use of new ID generator mappings."
}
},
{
"name": "spring.jpa.open-in-view",
"defaultValue": true
}
],
"hints": [
{
"name": "spring.jpa.hibernate.ddl-auto",
"values": [
{
"value": "create",
"description": "Create the schema and destroy previous data."
},
{
"value": "create-drop",
"description": "Create and then destroy the schema at the end of the session."
},
{
"value": "create-only",
"description": "Create the schema."
},
{
"value": "drop",
"description": "Drop the schema."
},
{
"value": "none",
"description": "Disable DDL handling."
},
{
"value": "truncate",
"description": "Truncate the tables in the schema."
},
{
"value": "update",
"description": "Update the schema if necessary."
},
{
"value": "validate",
"description": "Validate the schema, make no changes to the database."
}
]
},
{
"name": "spring.jpa.hibernate.naming.implicit-strategy",
"providers": [
{
"name": "class-reference",
"parameters": {
"target": "org.hibernate.boot.model.naming.ImplicitNamingStrategy"
}
}
]
},
{
"name": "spring.jpa.hibernate.naming.physical-strategy",
"providers": [
{
"name": "class-reference",
"parameters": {
"target": "org.hibernate.boot.model.naming.PhysicalNamingStrategy"
}
}
]
}
]
}
@@ -0,0 +1,7 @@
# Database Initializer Detectors
org.springframework.boot.sql.init.dependency.DatabaseInitializerDetector=\
org.springframework.boot.jpa.JpaDatabaseInitializerDetector
# Depends On Database Initialization Detectors
org.springframework.boot.sql.init.dependency.DependsOnDatabaseInitializationDetector=\
org.springframework.boot.jpa.JpaDependsOnDatabaseInitializationDetector
@@ -0,0 +1 @@
org.springframework.boot.jpa.autoconfigure.hibernate.HibernateJpaAutoConfiguration
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.autoconfigure.orm.jpa;
package org.springframework.boot.jpa.autoconfigure;
import java.io.File;
import java.lang.annotation.ElementType;
@@ -37,13 +37,13 @@ import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.TestAutoConfigurationPackage;
import org.springframework.boot.autoconfigure.data.jpa.country.Country;
import org.springframework.boot.autoconfigure.orm.jpa.test.City;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.boot.jdbc.autoconfigure.DataSourceAutoConfiguration;
import org.springframework.boot.jdbc.autoconfigure.DataSourceInitializationAutoConfiguration;
import org.springframework.boot.jdbc.autoconfigure.DataSourceTransactionManagerAutoConfiguration;
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
import org.springframework.boot.jpa.EntityManagerFactoryBuilder;
import org.springframework.boot.jpa.autoconfigure.test.city.City;
import org.springframework.boot.jpa.autoconfigure.test.country.Country;
import org.springframework.boot.test.context.assertj.AssertableApplicationContext;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.boot.test.context.runner.ContextConsumer;
@@ -78,7 +78,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Stephane Nicoll
* @author Yanming Zhou
*/
abstract class AbstractJpaAutoConfigurationTests {
public abstract class AbstractJpaAutoConfigurationTests {
private final Class<?> autoConfiguredClass;
@@ -318,7 +318,7 @@ abstract class AbstractJpaAutoConfigurationTests {
}
@Configuration(proxyBeanMethods = false)
static class TestTwoDataSourcesConfiguration {
protected static class TestTwoDataSourcesConfiguration {
@Bean
DataSource firstDataSource() {
@@ -360,7 +360,7 @@ abstract class AbstractJpaAutoConfigurationTests {
@Configuration(proxyBeanMethods = false)
@TestAutoConfigurationPackage(City.class)
static class TestConfiguration {
protected static class TestConfiguration {
}
@@ -516,12 +516,12 @@ abstract class AbstractJpaAutoConfigurationTests {
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence https://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="manually-configured">
<class>org.springframework.boot.autoconfigure.orm.jpa.test.City</class>
<class>org.springframework.boot.jpa.autoconfigure.test.city.City</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
</persistence-unit>
</persistence>
""")
@interface WithMetaInfPersistenceXmlResource {
protected @interface WithMetaInfPersistenceXmlResource {
}
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.autoconfigure.orm.jpa;
package org.springframework.boot.jpa.autoconfigure.hibernate;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
@@ -31,8 +31,9 @@ import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.TestAutoConfigurationPackage;
import org.springframework.boot.autoconfigure.orm.jpa.test.City;
import org.springframework.boot.jdbc.autoconfigure.DataSourceAutoConfiguration;
import org.springframework.boot.jpa.autoconfigure.JpaProperties;
import org.springframework.boot.jpa.autoconfigure.test.city.City;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -14,16 +14,20 @@
* limitations under the License.
*/
package org.springframework.boot.autoconfigure.orm.jpa;
package org.springframework.boot.jpa.autoconfigure.hibernate;
import javax.cache.CacheManager;
import javax.cache.Caching;
import org.ehcache.jsr107.EhcacheCachingProvider;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration;
import org.springframework.boot.jdbc.autoconfigure.DataSourceAutoConfiguration;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.jcache.JCacheCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import static org.assertj.core.api.Assertions.assertThat;
@@ -36,8 +40,8 @@ import static org.assertj.core.api.Assertions.assertThat;
class Hibernate2ndLevelCacheIntegrationTests {
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(CacheAutoConfiguration.class, DataSourceAutoConfiguration.class,
HibernateJpaAutoConfiguration.class))
.withConfiguration(
AutoConfigurations.of(DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class))
.withUserConfiguration(TestConfiguration.class);
@Test
@@ -54,6 +58,16 @@ class Hibernate2ndLevelCacheIntegrationTests {
@EnableCaching
static class TestConfiguration {
@Bean
CacheManager cacheManager() {
return Caching.getCachingProvider(EhcacheCachingProvider.class.getName()).getCacheManager();
}
@Bean
JCacheCacheManager jcacheCacheManager(CacheManager cacheManager) {
return new JCacheCacheManager(cacheManager);
}
}
}
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.autoconfigure.orm.jpa;
package org.springframework.boot.jpa.autoconfigure.hibernate;
import java.util.Collections;
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.autoconfigure.orm.jpa;
package org.springframework.boot.jpa.autoconfigure.hibernate;
import java.io.IOException;
import java.net.URL;
@@ -58,16 +58,18 @@ import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.TestAutoConfigurationPackage;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfigurationTests.JpaUsingApplicationListenerConfiguration.EventCapturingApplicationListener;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration.HibernateRuntimeHints;
import org.springframework.boot.autoconfigure.orm.jpa.mapping.NonAnnotatedEntity;
import org.springframework.boot.autoconfigure.orm.jpa.test.City;
import org.springframework.boot.flyway.autoconfigure.FlywayAutoConfiguration;
import org.springframework.boot.jdbc.autoconfigure.DataSourceTransactionManagerAutoConfiguration;
import org.springframework.boot.jdbc.autoconfigure.XADataSourceAutoConfiguration;
import org.springframework.boot.jpa.autoconfigure.AbstractJpaAutoConfigurationTests;
import org.springframework.boot.jpa.autoconfigure.EntityManagerFactoryBuilderCustomizer;
import org.springframework.boot.jpa.autoconfigure.hibernate.HibernateJpaAutoConfigurationTests.JpaUsingApplicationListenerConfiguration.EventCapturingApplicationListener;
import org.springframework.boot.jpa.autoconfigure.hibernate.HibernateJpaConfiguration.HibernateRuntimeHints;
import org.springframework.boot.jpa.autoconfigure.hibernate.mapping.NonAnnotatedEntity;
import org.springframework.boot.jpa.autoconfigure.test.city.City;
import org.springframework.boot.jpa.hibernate.SpringImplicitNamingStrategy;
import org.springframework.boot.jpa.hibernate.SpringJtaPlatform;
import org.springframework.boot.liquibase.autoconfigure.LiquibaseAutoConfiguration;
import org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy;
import org.springframework.boot.orm.jpa.hibernate.SpringJtaPlatform;
import org.springframework.boot.sql.init.dependency.DependsOnDatabaseInitialization;
import org.springframework.boot.test.context.assertj.AssertableApplicationContext;
import org.springframework.boot.test.context.runner.ContextConsumer;
@@ -390,7 +392,7 @@ class HibernateJpaAutoConfigurationTests extends AbstractJpaAutoConfigurationTes
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence/orm https://www.oracle.com/webfolder/technetwork/jsc/xml/ns/persistence/orm_2_1.xsd"
version="2.1">
<entity class="org.springframework.boot.autoconfigure.orm.jpa.mapping.NonAnnotatedEntity">
<entity class="org.springframework.boot.jpa.autoconfigure.hibernate.mapping.NonAnnotatedEntity">
<table name="NON_ANNOTATED"/>
<attributes>
<id name="id">
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.autoconfigure.orm.jpa;
package org.springframework.boot.jpa.autoconfigure.hibernate;
import java.util.Map;
import java.util.function.Consumer;
@@ -30,7 +30,8 @@ import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy;
import org.springframework.boot.jpa.autoconfigure.JpaProperties;
import org.springframework.boot.jpa.hibernate.SpringImplicitNamingStrategy;
import org.springframework.boot.test.context.assertj.AssertableApplicationContext;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.boot.test.context.runner.ContextConsumer;
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.autoconfigure.orm.jpa.mapping;
package org.springframework.boot.jpa.autoconfigure.hibernate.mapping;
/**
* A non annotated entity that is handled by a custom "mapping-file".
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.autoconfigure.orm.jpa.test;
package org.springframework.boot.jpa.autoconfigure.test.city;
import java.io.Serializable;
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.autoconfigure.orm.jpa.test;
package org.springframework.boot.jpa.autoconfigure.test.city;
import jakarta.persistence.PostLoad;
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.boot.autoconfigure.orm.jpa.domain.country;
package org.springframework.boot.jpa.autoconfigure.test.country;
import java.io.Serializable;
@@ -21,9 +21,9 @@ plugins {
description = "Starter for using Spring Data JPA with Hibernate"
dependencies {
api(project(":spring-boot-project:spring-boot-jpa"))
api(project(":spring-boot-project:spring-boot-starters:spring-boot-starter"))
api(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-jdbc"))
api("org.hibernate.orm:hibernate-core")
api("org.springframework.data:spring-data-jpa")
api("org.springframework:spring-aspects")
}
@@ -58,6 +58,7 @@ dependencies {
optional(project(":spring-boot-project:spring-boot-groovy-templates"))
optional(project(":spring-boot-project:spring-boot-jackson"))
optional(project(":spring-boot-project:spring-boot-jdbc"))
optional(project(":spring-boot-project:spring-boot-jpa"))
optional(project(":spring-boot-project:spring-boot-jsonb"))
optional(project(":spring-boot-project:spring-boot-liquibase")) {
exclude(group: "org.liquibase")
@@ -21,7 +21,6 @@ import jakarta.persistence.EntityManagerFactory;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.context.annotation.Bean;
/**
@@ -31,7 +30,7 @@ import org.springframework.context.annotation.Bean;
* @since 1.4.0
* @see AutoConfigureTestEntityManager
*/
@AutoConfiguration(after = HibernateJpaAutoConfiguration.class)
@AutoConfiguration(afterName = "org.springframework.boot.jpa.autoconfigure.hibernate.HibernateJpaAutoConfiguration")
@ConditionalOnClass({ EntityManagerFactory.class })
public class TestEntityManagerAutoConfiguration {
@@ -1,6 +1,6 @@
# AutoConfigureDataJpa auto-configuration imports
org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration
org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration
org.springframework.boot.jpa.autoconfigure.hibernate.HibernateJpaAutoConfiguration
org.springframework.boot.jdbc.autoconfigure.DataSourceAutoConfiguration
org.springframework.boot.jdbc.autoconfigure.DataSourceInitializationAutoConfiguration
org.springframework.boot.jdbc.autoconfigure.DataSourceTransactionManagerAutoConfiguration
@@ -24,10 +24,8 @@ dependencies {
implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-freemarker"))
implementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-web"))
implementation(project(":spring-boot-project:spring-boot-jdbc"))
implementation("jakarta.persistence:jakarta.persistence-api")
implementation(project(":spring-boot-project:spring-boot-jpa"))
implementation("jakarta.xml.bind:jakarta.xml.bind-api")
implementation("org.hibernate.orm:hibernate-core")
implementation("org.springframework:spring-orm")
runtimeOnly("com.h2database:h2")
runtimeOnly("jakarta.transaction:jakarta.transaction-api")