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:
Stephane Nicoll 2015-06-08 14:20:50 +02:00
parent 20cd6c4b6a
commit 3dcd8e2346
2 changed files with 24 additions and 6 deletions

View File

@ -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)) {

View File

@ -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 {