Skip to content
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

Database migrations may not have run before NamedParameterJdbcTemplate is used #16032

Closed
xak2000 opened this issue Feb 25, 2019 · 3 comments
Closed
Labels
status: superseded An issue that has been superseded by another type: bug A general bug

Comments

@xak2000
Copy link
Contributor

xak2000 commented Feb 25, 2019

This is a variation of already fixed issue with JdbcTemplate #13155. But this is for NamedParameterJdbcTemplate.

The fix (4881925) doesn't take into account another kind of JdbcTemplate - NamedParameterJdbcTemplate, which implements NamedParameterJdbcOperations (and doesn't implement JdbcOperations).

So, if an application doesn't create JdbcTemplate bean but only creates NamedParameterJdbcTemplate bean (using it's NamedParameterJdbcTemplate(DataSource dataSource) constructor), this bean still created before migration tool (e.g. Flyway) runs their migrations. So any @PostConstruct, that uses NamedParameterJdbcTemplate, runs earlier than migration. What is worse: there is not always the case. Sometimes migrations runs earlier. I think this is more or less "random" order because there is no explicit @DependsOn here.

So I think it's need to create a NamedParameterJdbcOperationsDependsOnPostProcessor in line with JdbcOperationsDependsOnPostProcessor and Flyway/Liqbase childs of it.

Spring Boot version tested: 2.0.5. But I don't see any NamedParameterJdbcOperations postprocessors in master, so I think this bug affects current version too.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Feb 25, 2019
@snicoll snicoll added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Feb 26, 2019
@snicoll snicoll added this to the 2.1.x milestone Feb 26, 2019
@clevertension
Copy link
Contributor

@snicoll are you working to fix this bug? if not, i can provide a PR ASAP

@snicoll
Copy link
Member

snicoll commented Feb 26, 2019

Thanks for the offer. Please proceed and I am happy to review your contribution.

@snicoll
Copy link
Member

snicoll commented Feb 27, 2019

Closing in favour of PR #16047

@snicoll snicoll closed this as completed Feb 27, 2019
@snicoll snicoll added the status: superseded An issue that has been superseded by another label Feb 27, 2019
@snicoll snicoll removed this from the 2.1.x milestone Feb 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: superseded An issue that has been superseded by another type: bug A general bug
Projects
None yet
Development

No branches or pull requests

4 participants