-
Notifications
You must be signed in to change notification settings - Fork 41k
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
When an application contains multiple DataSource beans, EntityManagerFactoryBuilder will default ddl-auto to a value that may only be appropriate for the primary DataSource #44516
Comments
Please provide a minimal sample that reproduces the behavior you have described. There are too many unknowns at the moment in terms of how the two databases and the entity managers that depend on them are configured. |
@wilkinsona thanks for your reply. Sure, here's a minimal project that reproduces described behavior: https://github.com/randomComitter/dropcreate |
Thanks for the sample. The change in behavior is due to this change. The You're injecting the I think the ideal here would be that configuring the |
ddl-auto
to a value that may only be appropriate for the primary DataSource
ddl-auto
to a value that may only be appropriate for the primary DataSource
Thank you very much for the explanations and the proposed solution. Indeed, if I move At least we didn’t expect that a minor version update would damage our database (luckily it was just a test database), which has made us more cautious about similar changes in the future. My current understanding of the issue is as follows. If the primary data source is an embedded database and the property If my understanding is correct, this raises two important questions:
As an additional note which might be worth mentioning: when |
This is merely a workaround for the time being. As for the rest, this issue is opened and flagged for resolution in the next maintenance release of Spring Boot. This is a regression and we're going to fix it. Please give it a try (in particular with your note about the H2 console) once a snapshot is available with the fix. I tried to run your sample but it requires to setup a MySQL instance. It would have been preferable to provide one with the sample (via a docker command or a docker compose file). |
After updating Spring Boot from 3.3.5 to 3.4.3, the default
ddl-auto
create-drop
will be applied to the non-embedded database if project has two databases, one of them is an embedded db and no explicit value is set forspring.jpa.hibernate.ddl-auto
in application properties.Is this a bug or an intended behavior?
The current documentation for Database Initialization mentions the following:
which gives impression that create-drop will be applied by default only to the embedded database.
However, sometime between Spring Boot 3.3.5 and 3.4.3 a change was made so that default value
create-drop
forspring.jpa.hibernate.ddl-auto
was applied to all data sources whether they were embedded or not (if at least one of them was embedded), which is dangerous behaviour and can lead to unexpected data loss in production databases.The text was updated successfully, but these errors were encountered: