-
Notifications
You must be signed in to change notification settings - Fork 41.6k
javax.persistence.schema-generation.database.action is ignored when checking if default DDL auto setting should be applied #25129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,6 +35,7 @@ | |
| * Configuration properties for Hibernate. | ||
| * | ||
| * @author Stephane Nicoll | ||
| * @author Chris Bono | ||
| * @since 2.1.0 | ||
| * @see JpaProperties | ||
| */ | ||
|
|
@@ -133,6 +134,21 @@ private String determineDdlAuto(Map<String, String> existing, Supplier<String> d | |
| if (ddlAuto != null) { | ||
| return ddlAuto; | ||
| } | ||
| String ddlDatabaseAction = existing.get(AvailableSettings.HBM2DDL_DATABASE_ACTION); | ||
| if (ddlDatabaseAction != null) { | ||
|
||
| if (ddlDatabaseAction.equals("none")) { | ||
| return "none"; | ||
| } | ||
| if (ddlDatabaseAction.equals("create")) { | ||
| return "create-only"; | ||
| } | ||
| if (ddlDatabaseAction.equals("drop")) { | ||
| return "drop"; | ||
| } | ||
| if (ddlDatabaseAction.equals("drop-and-create")) { | ||
| return "create"; | ||
| } | ||
| } | ||
| return (this.ddlAuto != null) ? this.ddlAuto : defaultDdlAuto.get(); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,10 +19,15 @@ | |
| import java.util.Map; | ||
| import java.util.function.Consumer; | ||
| import java.util.function.Supplier; | ||
| import java.util.stream.Stream; | ||
|
|
||
| import org.hibernate.cfg.AvailableSettings; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.params.ParameterizedTest; | ||
| import org.junit.jupiter.params.provider.Arguments; | ||
| import org.junit.jupiter.params.provider.MethodSource; | ||
| import org.junit.jupiter.params.provider.ValueSource; | ||
| import org.mockito.Mock; | ||
| import org.mockito.MockitoAnnotations; | ||
|
|
||
|
|
@@ -44,6 +49,7 @@ | |
| * | ||
| * @author Stephane Nicoll | ||
| * @author Artsiom Yudovin | ||
| * @author Chris Bono | ||
| */ | ||
| class HibernatePropertiesTests { | ||
|
|
||
|
|
@@ -135,9 +141,37 @@ void defaultDdlAutoIsNotInvokedIfHibernateSpecificPropertyIsSet() { | |
| .run(assertDefaultDdlAutoNotInvoked("create")); | ||
| } | ||
|
|
||
| @ParameterizedTest | ||
| @MethodSource("validJpaDatabaseActionsToExpectedHbmValues") | ||
| void defaultDdlAutoIsNotInvokedIfJpaDatabaseActionPropertyIsSetToValidJpaValue(String jpaDatabaseAction, | ||
|
||
| String expectedHbmDdlAuto) { | ||
| this.contextRunner.withPropertyValues( | ||
| "spring.jpa.properties.javax.persistence.schema-generation.database.action=" + jpaDatabaseAction) | ||
| .run(assertDefaultDdlAutoNotInvoked(expectedHbmDdlAuto)); | ||
| } | ||
|
|
||
| private static Stream<Arguments> validJpaDatabaseActionsToExpectedHbmValues() { | ||
| return Stream.of(Arguments.of("none", null), Arguments.of("create", "create-only"), | ||
| Arguments.of("drop", "drop"), Arguments.of("drop-and-create", "create")); | ||
| } | ||
|
|
||
| @ParameterizedTest | ||
| @ValueSource(strings = { "create-only", "create-drop", "validate", "update" }) | ||
| void defaultDdlAutoIsInvokedIfJpaDatabaseActionPropertyIsSetToNonJpaValue(String nonJpaDatabaseActionValue) { | ||
| this.contextRunner | ||
| .withPropertyValues("spring.jpa.properties.javax.persistence.schema-generation.database.action=" | ||
| + nonJpaDatabaseActionValue) | ||
| .run(assertHibernateProperties((hibernateProperties) -> verify(this.ddlAutoSupplier).get())); | ||
| } | ||
|
|
||
| private ContextConsumer<AssertableApplicationContext> assertDefaultDdlAutoNotInvoked(String expectedDdlAuto) { | ||
| return assertHibernateProperties((hibernateProperties) -> { | ||
| assertThat(hibernateProperties).containsEntry(AvailableSettings.HBM2DDL_AUTO, expectedDdlAuto); | ||
| if (expectedDdlAuto == null) { | ||
| assertThat(hibernateProperties).doesNotContainKey(AvailableSettings.HBM2DDL_AUTO); | ||
| } | ||
| else { | ||
| assertThat(hibernateProperties).containsEntry(AvailableSettings.HBM2DDL_AUTO, expectedDdlAuto); | ||
| } | ||
| verify(this.ddlAutoSupplier, never()).get(); | ||
| }); | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.