parent
99dae09f84
commit
fbe53be6c1
|
@ -26,6 +26,7 @@ import org.junit.After;
|
|||
import org.junit.Test;
|
||||
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.boot.orm.jpa.hibernate.SpringNamingStrategy;
|
||||
import org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy;
|
||||
import org.springframework.boot.test.util.EnvironmentTestUtils;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
|
@ -53,6 +54,18 @@ public class JpaPropertiesTests {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hibernate4NoCustomNamingStrategy() throws Exception {
|
||||
JpaProperties properties = load(HibernateVersion.V4);
|
||||
Map<String, String> hibernateProperties = properties
|
||||
.getHibernateProperties(mockStandaloneDataSource());
|
||||
assertThat(hibernateProperties).contains(entry("hibernate.ejb.naming_strategy",
|
||||
SpringNamingStrategy.class.getName()));
|
||||
assertThat(hibernateProperties).doesNotContainKeys(
|
||||
"hibernate.implicit_naming_strategy",
|
||||
"hibernate.physical_naming_strategy");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hibernate4CustomNamingStrategy() throws Exception {
|
||||
JpaProperties properties = load(HibernateVersion.V4,
|
||||
|
@ -163,8 +176,7 @@ public class JpaPropertiesTests {
|
|||
ctx.register(TestConfiguration.class);
|
||||
ctx.refresh();
|
||||
this.context = ctx;
|
||||
JpaProperties properties = this.context.getBean(JpaProperties.class);
|
||||
return properties;
|
||||
return this.context.getBean(JpaProperties.class);
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
|
|
@ -1619,18 +1619,16 @@ configuration properties. The most common options to set are:
|
|||
|
||||
[indent=0,subs="verbatim,quotes,attributes"]
|
||||
----
|
||||
spring.jpa.hibernate.ddl-auto: create-drop
|
||||
spring.jpa.hibernate.naming_strategy: org.hibernate.cfg.ImprovedNamingStrategy
|
||||
spring.jpa.database: H2
|
||||
spring.jpa.show-sql: true
|
||||
spring.jpa.hibernate.ddl-auto=create-drop
|
||||
spring.jpa.hibernate.naming.physical-strategy=com.example.MyPhysicalNamingStrategy
|
||||
spring.jpa.database=H2
|
||||
spring.jpa.show-sql=true
|
||||
----
|
||||
|
||||
(Because of relaxed data binding hyphens or underscores should work equally well as
|
||||
property keys.) The `ddl-auto` setting is a special case in that it has different
|
||||
defaults depending on whether you are using an embedded database (`create-drop`) or not
|
||||
(`none`). In addition all properties in `+spring.jpa.properties.*+` are passed through as
|
||||
normal JPA properties (with the prefix stripped) when the local `EntityManagerFactory` is
|
||||
created.
|
||||
The `ddl-auto` setting is a special case in that it has different defaults depending on
|
||||
whether you are using an embedded database (`create-drop`) or not (`none`). In addition
|
||||
all properties in `+spring.jpa.properties.*+` are passed through as normal JPA properties
|
||||
(with the prefix stripped) when the local `EntityManagerFactory` is created.
|
||||
|
||||
See {sc-spring-boot-autoconfigure}/orm/jpa/HibernateJpaAutoConfiguration.{sc-ext}[`HibernateJpaAutoConfiguration`]
|
||||
and {sc-spring-boot-autoconfigure}/orm/jpa/JpaBaseConfiguration.{sc-ext}[`JpaBaseConfiguration`]
|
||||
|
|
|
@ -16,9 +16,7 @@
|
|||
|
||||
package org.springframework.boot.orm.jpa.hibernate;
|
||||
|
||||
import org.hibernate.Hibernate;
|
||||
import org.hibernate.cfg.ImprovedNamingStrategy;
|
||||
import org.hibernate.cfg.NamingStrategy;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
|
@ -33,10 +31,7 @@ import org.springframework.util.StringUtils;
|
|||
* @author Phillip Webb
|
||||
* @see "http://stackoverflow.com/questions/7689206/ejb3namingstrategy-vs-improvednamingstrategy-foreign-key-naming"
|
||||
* @since 1.2.0
|
||||
* @deprecated as of 1.4 since {@link NamingStrategy} is no longer used by
|
||||
* {@link Hibernate}. Consider using {@link SpringPhysicalNamingStrategy}
|
||||
*/
|
||||
@Deprecated
|
||||
@SuppressWarnings("serial")
|
||||
public class SpringNamingStrategy extends ImprovedNamingStrategy {
|
||||
|
||||
|
|
Loading…
Reference in New Issue