|
25 | 25 | import java.util.Enumeration;
|
26 | 26 | import java.util.List;
|
27 | 27 | import java.util.Map;
|
| 28 | +import java.util.function.Consumer; |
28 | 29 |
|
29 | 30 | import javax.persistence.EntityManager;
|
30 | 31 | import javax.persistence.EntityManagerFactory;
|
|
37 | 38 | import org.hibernate.boot.model.naming.ImplicitNamingStrategy;
|
38 | 39 | import org.hibernate.boot.model.naming.PhysicalNamingStrategy;
|
39 | 40 | import org.hibernate.cfg.AvailableSettings;
|
| 41 | +import org.hibernate.dialect.H2Dialect; |
40 | 42 | import org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform;
|
41 | 43 | import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform;
|
42 | 44 | import org.hibernate.internal.SessionFactoryImpl;
|
|
65 | 67 | import org.springframework.context.annotation.Bean;
|
66 | 68 | import org.springframework.context.annotation.Configuration;
|
67 | 69 | import org.springframework.orm.jpa.JpaTransactionManager;
|
| 70 | +import org.springframework.orm.jpa.JpaVendorAdapter; |
68 | 71 | import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
|
| 72 | +import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; |
69 | 73 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
70 | 74 |
|
71 | 75 | import static org.assertj.core.api.Assertions.assertThat;
|
@@ -155,6 +159,40 @@ public void testLiquibasePlusValidation() {
|
155 | 159 | .run((context) -> assertThat(context).hasNotFailed());
|
156 | 160 | }
|
157 | 161 |
|
| 162 | + @Test |
| 163 | + public void hibernateDialectIsNotSetByDefault() { |
| 164 | + contextRunner().run(assertJpaVendorAdapter( |
| 165 | + (adapter) -> assertThat(adapter.getJpaPropertyMap()) |
| 166 | + .doesNotContainKeys("hibernate.dialect"))); |
| 167 | + } |
| 168 | + |
| 169 | + @Test |
| 170 | + public void hibernateDialectIsSetWhenDatabaseIsSet() { |
| 171 | + contextRunner().withPropertyValues("spring.jpa.database=H2") |
| 172 | + .run(assertJpaVendorAdapter( |
| 173 | + (adapter) -> assertThat(adapter.getJpaPropertyMap()).contains( |
| 174 | + entry("hibernate.dialect", H2Dialect.class.getName())))); |
| 175 | + } |
| 176 | + |
| 177 | + @Test |
| 178 | + public void hibernateDialectIsSetWhenDatabasePlatformIsSet() { |
| 179 | + String databasePlatform = TestH2Dialect.class.getName(); |
| 180 | + contextRunner() |
| 181 | + .withPropertyValues("spring.jpa.database-platform=" + databasePlatform) |
| 182 | + .run(assertJpaVendorAdapter( |
| 183 | + (adapter) -> assertThat(adapter.getJpaPropertyMap()) |
| 184 | + .contains(entry("hibernate.dialect", databasePlatform)))); |
| 185 | + } |
| 186 | + |
| 187 | + private ContextConsumer<AssertableApplicationContext> assertJpaVendorAdapter( |
| 188 | + Consumer<HibernateJpaVendorAdapter> adapter) { |
| 189 | + return (context) -> { |
| 190 | + assertThat(context).hasSingleBean(JpaVendorAdapter.class); |
| 191 | + assertThat(context).hasSingleBean(HibernateJpaVendorAdapter.class); |
| 192 | + adapter.accept(context.getBean(HibernateJpaVendorAdapter.class)); |
| 193 | + }; |
| 194 | + } |
| 195 | + |
158 | 196 | @Test
|
159 | 197 | public void jtaDefaultPlatform() {
|
160 | 198 | contextRunner()
|
@@ -597,4 +635,8 @@ public EntityManagerFactoryBuilderCustomizer asyncBootstrappingCustomizer(
|
597 | 635 |
|
598 | 636 | }
|
599 | 637 |
|
| 638 | + public static class TestH2Dialect extends H2Dialect { |
| 639 | + |
| 640 | + } |
| 641 | + |
600 | 642 | }
|
0 commit comments