-
Notifications
You must be signed in to change notification settings - Fork 41.2k
Multiple Datasources and JPA obey Principle of Least Astonishment #10604
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Do you have a suggestion as to how this could be simplified? How would you expect Spring Boot to infer that you want multiple DataSources, multiple EntityManagers etc? |
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed. |
Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue. |
Reopen please? I have suggestions for the simple case of multiple databases. Defining multiple
It would be nice if I didn't have to specify the type, and Boot would automatically apply the auto-configured type, corresponding vendor properties, and initialization. It's the EMFs that are the real pain. If you are separating everything by package scan then it's not too bad, though you need to do some copy-pasting of private methods and hard-coding of Hibernate to get the vendor properties with defaults and customizers. Some duplication would be saved if the Downsides of package separation include having to refactor packages to change datasources, and not being able to have multiple EMFs for the same type. Any other method for assigning entities becomes a bit of a nightmare (for repositories it's manageable, because I think an even better solution is to make use of the |
@OrangeDog Thanks for sharing your thoughts. We've now got #15732 which has superseded this issue. |
@wilkinsona that doesn't cover the JPA stuff though? |
It says:
We can't really know what JPA, transaction management etc will look like until we're figured out the |
I see. I'm not looking for full autoconfiguration, just slightly easier custom configuration that doesn't have to duplicate everything the Boot would've done. As I mentioned above, a small first change that would be helpful is if the If you do put in full multi-JPA autoconfiguration and I want something slightly different, I don't want to be back to doing everything myself again. |
A surprising amount of work--entirely boilerplate--is currently necessary for a Spring Boot app to utilize two (or more) Datasources with JPA. There is fantastic support for a single implicit Datasource (and autowiring it for JPA use) by configuring a handful of properties. By comparison an extraordinary amount of work--annotations and interfaces/classes--are requried to support a second Datasource with JPA (
EnableTransactionManagement
,EnableJpaRepositories
,EntityManagerFactory
,EntityManagerFactoryBuilder
,PlatformTransactionManager
,JpaTransactionManager
,DataSourceBuilder
,LocalContainerEntityManagerFactoryBean
, ...)This issue proposes that Spring Boot configuration guidelines--and supporting changes to autowiring--be developed such that adding additional Datasources for JPA doesn't require departing from a configuration-over-code mindset. The current approach certainly falls afoul of the Principle of Least Astonishment:
The fact that so many developers spend time troubleshooting and discussing how to accomplish this is good evidence that a simplification is in order.
See also:
The text was updated successfully, but these errors were encountered: