Support for Hibernate naming strategy delegator
hibernate.ejb.naming_strategy_delegator and hibernate.ejb.naming_strategy cannot be used at the same time but Boot sets the latter automatically. We now only set the naming strategy if no delegator has been specified via configuration Closes gh-3149
This commit is contained in:
parent
20cd6c4b6a
commit
3dcd8e2346
|
|
@ -158,12 +158,14 @@ public class JpaProperties {
|
|||
private Map<String, String> getAdditionalProperties(Map<String, String> existing,
|
||||
DataSource dataSource) {
|
||||
Map<String, String> result = new HashMap<String, String>(existing);
|
||||
if (!isAlreadyProvided(existing, "ejb.naming_strategy")
|
||||
&& this.namingStrategy != null) {
|
||||
result.put("hibernate.ejb.naming_strategy", this.namingStrategy.getName());
|
||||
}
|
||||
else if (this.namingStrategy == null) {
|
||||
result.put("hibernate.ejb.naming_strategy", DEFAULT_NAMING_STRATEGY);
|
||||
if (!isAlreadyProvided(existing, "ejb.naming_strategy_delegator")) {
|
||||
if (!isAlreadyProvided(existing, "ejb.naming_strategy")
|
||||
&& this.namingStrategy != null) {
|
||||
result.put("hibernate.ejb.naming_strategy", this.namingStrategy.getName());
|
||||
}
|
||||
else if (this.namingStrategy == null) {
|
||||
result.put("hibernate.ejb.naming_strategy", DEFAULT_NAMING_STRATEGY);
|
||||
}
|
||||
}
|
||||
String ddlAuto = getOrDeduceDdlAuto(existing, dataSource);
|
||||
if (StringUtils.hasText(ddlAuto) && !"none".equals(ddlAuto)) {
|
||||
|
|
|
|||
|
|
@ -84,6 +84,22 @@ public class CustomHibernateJpaAutoConfigurationTests {
|
|||
assertThat(actual, equalTo("create-drop"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNamingStrategyDelegatorTakesPrecedence() {
|
||||
EnvironmentTestUtils.addEnvironment(this.context,
|
||||
"spring.jpa.properties.hibernate.ejb.naming_strategy_delegator:" +
|
||||
"org.hibernate.cfg.naming.ImprovedNamingStrategyDelegator");
|
||||
this.context.register(TestConfiguration.class,
|
||||
EmbeddedDataSourceConfiguration.class,
|
||||
PropertyPlaceholderAutoConfiguration.class,
|
||||
HibernateJpaAutoConfiguration.class);
|
||||
this.context.refresh();
|
||||
JpaProperties bean = this.context.getBean(JpaProperties.class);
|
||||
DataSource dataSource = this.context.getBean(DataSource.class);
|
||||
assertThat(bean.getHibernateProperties(dataSource).get(
|
||||
"hibernate.ejb.naming_strategy"), nullValue());
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@TestAutoConfigurationPackage(City.class)
|
||||
protected static class TestConfiguration {
|
||||
|
|
|
|||
Loading…
Reference in New Issue