spring-projects / spring-projects/spring-boot
EntityManagerFactoryBuilder does not apply spring.jpa.hibernate customizations automatically
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 81.5k
- Forks
- 42.7k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 65
Description
When using a single data source and entity manager in a Spring Boot JPA project, the hibernate settings are picked up from the application properties (e.g., the application.yml file) and applied as expected.
In the case of multiple data source and entity managers, the naming_strategy setting is not applied and thus we get the default naming strategy. A minor bug with a likely quick fix I imagine.
I've put together a sample project showing the issue:
https://github.com/eepstein/multids-demo
(which was forked from https://github.com/gratiartis/multids-demo)
The relevant lines are in the FooConfig and BarConfig classes. For example, from com.sctrcd.multidsdemo.integration.config.foo.FooConfig:
// This is to work-around a bug in Spring boot, which is not setting the naming strategy when there
// are multiple data sources and entity managers.
.properties(Collections.singletonMap("hibernate.ejb.naming_strategy",
jpaProperties.getHibernate().getNamingStrategy()))
If you comment out that line you'll see an assertion in the test will fail, even though the naming strategy is being correctly set in the application-test.yml file in the test resources folder.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with FooConfig and BarConfig in the multids-demo sample, then inspect application-test.yml and run the test with the naming-strategy workaround commented out. Compare the single- and multiple-entity-manager paths to locate where the configured naming strategy is lost. Done means the assertion passes without the manual properties workaround.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring-boot
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100