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
DatabasePopulatorUtils.execute should commit if the current Connection has auto-commit set to false #27008
Comments
…mit mode false When initialize spring-batch tables with postgresql datasource in auto-commit mode false, the tables are created in the database. In ScriptUtils.executeSqlScript, after executing statement, there is not an explicit commit. So that, when postgresql datasource is in auto-commit mode false, transaction is not committed I added an explicit commit after executing statement when auto-commit mode is false Fixes https://github.com/spring-projects/spring-boot/issues/25318
…mit mode false When initialize spring-batch tables with postgresql datasource in auto-commit mode false, the tables are not created in the database. In ScriptUtils.executeSqlScript, after executing statement, there is not an explicit commit. So that, when postgresql datasource is in auto-commit mode false, transaction is not committed I added an explicit commit after executing statement when auto-commit mode is false Fixes spring-projects/spring-boot#25318
…mit mode false When initialize spring-batch tables with postgresql datasource in auto-commit mode false, the tables are not created in the database. In ScriptUtils.executeSqlScript, after executing statement, there is not an explicit commit. So that, when postgresql datasource is in auto-commit mode false, transaction is not committed I added an explicit commit after executing statement when auto-commit mode is false Fixes spring-projects/spring-boot#25318
See this related thread. I think that |
After discussing with the framework team, we've decided to fix this in framework itself so I've moved this issue accordingly. |
This has been addressed in 89c7797 and will be available in 5.3.11 snapshots in a few minutes in case you want to try it out immediately. Otherwise, you can wait for the 5.3.11 release which is tentatively scheduled for tomorrow. |
We had an issue with this change that I think might be interesting to note. In our testrig we use a homegrown LiquibaseDatabasePopulator. We run C3P0 as connection pool. In our populator we have a try-finally and creates a
I'm not sure if I should report this as a bug or anything particular, but I think i might be good if anyone else come across with the same kind of error. The error says that you cannot operate on a closed connection. But the connection sent into the populate function was not closed.
|
Hi @eivinhb, Thanks for the feedback.
That sounds like the best course of action to me.
Good point. I added a note on that to the Javadoc in fb312d0. |
Nice. Thank you for replying. Just to be clear about this. It's closing the connection inside an implemention of DatabasePopulator.populate that cause an error in DatabasePopulatorUtil. |
Yep, that's the method I added the warning to in fb312d0. Feel free to review that commit. |
Hello,
I would like to submit an issue. I am facing a problem with creation of spring-batch tables when you use a datasource in
auto-commit mode => false;
My project is using spring-boot@2.2.7 and postgresql.
Here is my configuration :
I have checked the
BatchDataSourceInitializer
class which is the subclass ofAbstractDataSourceInitializer
.It appears that the code at line 65
DatabasePopulatorUtils.execute(populator, this.dataSource);
is responsible for running the sql script of spring-batch tables, with spring-jdbc, but the transaction is never committed.And consequently, my tables are never created in my database.
If I switch the configuration of my datasource, ie
auto-commit: true
, everything is working fine.I was expecting my spring-batch tables be created (initialize-schema => always) even if my datasource is not in auto-commit mode.
It's not so easy and not very intuitive, at first sight, to discover why the tables are not created. We first think about a misconfiguration relative to spring-batch but nothing related to datasource configuration.
What do you think about that ?
Thanks for your help.
The text was updated successfully, but these errors were encountered: