Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
49b75931
Commit
49b75931
authored
Aug 21, 2013
by
Phillip Webb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow hibernate naming strategy to be specified
Issue: #53028397
parent
580ec272
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
3 deletions
+32
-3
HibernateJpaAutoConfiguration.java
.../autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.java
+10
-2
HibernateJpaAutoConfigurationTests.java
...configure/orm/jpa/HibernateJpaAutoConfigurationTests.java
+22
-1
No files found.
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.java
View file @
49b75931
...
...
@@ -63,6 +63,9 @@ public class HibernateJpaAutoConfiguration extends JpaBaseConfiguration {
@Value
(
"${spring.jpa.ddlAuto:${spring.jpa.ddl_auto:none}}"
)
private
String
ddlAuto
;
// e.g. none, validate, update, create, create-drop
@Value
(
"${spring.jpa.hibernate.namingstrategy:org.hibernate.cfg.ImprovedNamingStrategy}"
)
private
String
namingStrategy
;
@Bean
@Override
public
JpaVendorAdapter
jpaVendorAdapter
()
{
...
...
@@ -81,8 +84,13 @@ public class HibernateJpaAutoConfiguration extends JpaBaseConfiguration {
Map
<
String
,
Object
>
properties
=
entityManagerFactoryBean
.
getJpaPropertyMap
();
properties
.
put
(
"hibernate.cache.provider_class"
,
"org.hibernate.cache.HashtableCacheProvider"
);
properties
.
put
(
"hibernate.ejb.naming_strategy"
,
ImprovedNamingStrategy
.
class
.
getName
());
if
(
StringUtils
.
hasLength
(
this
.
namingStrategy
))
{
properties
.
put
(
"hibernate.ejb.naming_strategy"
,
this
.
namingStrategy
);
}
else
{
properties
.
put
(
"hibernate.ejb.naming_strategy"
,
ImprovedNamingStrategy
.
class
.
getName
());
}
if
(
StringUtils
.
hasLength
(
this
.
ddlAuto
)
&&
!
"none"
.
equals
(
this
.
ddlAuto
))
{
properties
.
put
(
"hibernate.hbm2ddl.auto"
,
this
.
ddlAuto
);
}
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfigurationTests.java
View file @
49b75931
...
...
@@ -25,7 +25,6 @@ import org.springframework.boot.autoconfigure.ComponentScanDetectorConfiguration
import
org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration
;
import
org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration
;
import
org.springframework.boot.autoconfigure.jdbc.EmbeddedDatabaseConfiguration
;
import
org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration
;
import
org.springframework.boot.autoconfigure.orm.jpa.test.City
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
...
...
@@ -33,12 +32,15 @@ import org.springframework.context.annotation.Bean;
import
org.springframework.context.annotation.ComponentScan
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.orm.jpa.JpaTransactionManager
;
import
org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean
;
import
org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter
;
import
org.springframework.orm.jpa.support.OpenEntityManagerInViewInterceptor
;
import
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
;
import
static
org
.
hamcrest
.
Matchers
.
equalTo
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
/**
...
...
@@ -118,6 +120,25 @@ public class HibernateJpaAutoConfigurationTests {
assertEquals
(
0
,
getInterceptorBeans
().
length
);
}
@Test
public
void
testCustomNamingStrategy
()
throws
Exception
{
AnnotationConfigWebApplicationContext
context
=
new
AnnotationConfigWebApplicationContext
();
TestUtils
.
addEnviroment
(
context
,
"spring.jpa.hibernate.namingstrategy:org.hibernate.cfg.EJB3NamingStrategy"
);
context
.
register
(
TestConfiguration
.
class
,
ComponentScanDetectorConfiguration
.
class
,
EmbeddedDatabaseConfiguration
.
class
,
HibernateJpaAutoConfiguration
.
class
,
PropertyPlaceholderAutoConfiguration
.
class
);
this
.
context
=
context
;
this
.
context
.
refresh
();
LocalContainerEntityManagerFactoryBean
bean
=
this
.
context
.
getBean
(
LocalContainerEntityManagerFactoryBean
.
class
);
String
actual
=
(
String
)
bean
.
getJpaPropertyMap
().
get
(
"hibernate.ejb.naming_strategy"
);
assertThat
(
actual
,
equalTo
(
"org.hibernate.cfg.EJB3NamingStrategy"
));
}
private
String
[]
getInterceptorBeans
()
{
return
this
.
context
.
getBeanNamesForType
(
OpenEntityManagerInViewInterceptor
.
class
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment