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

DataSourceInitializedEvent picks wrong datasource #17061

Closed
m-kay opened this issue Jun 5, 2019 · 3 comments
Closed

DataSourceInitializedEvent picks wrong datasource #17061

m-kay opened this issue Jun 5, 2019 · 3 comments
Labels
type: bug A general bug
Milestone

Comments

@m-kay
Copy link
Contributor

m-kay commented Jun 5, 2019

With spring boot 2.1.x the DataSourceInitializedEvent picks the wrong datasource again because the property to get the datasource from the EntityManagerFactory changed to hibernate.connection.datasource compared to javax.persistence.nonJtaDataSource used in the fix for #8296.

As a workaround one can fix this by passing the legacy property javax.persistence.nonJtaDataSource to the EntityManagerFactoryBuilder with the correct datasource. I have created a minimal example with everything needed to initialize two datasources at https://github.com/m-kay/spring-boot-init-two-datasources and you can see the fix in FirstDbConfigline 84 and SecondDbConfig line 83. I had to create my own DataSourceInitializer which executes init scripts after the event is fired for my second datasource, since the defaults only work with a single datasource.

@philwebb
Copy link
Member

Thanks for the sample application @m-kay. I think that this might be a bug in recent Hibernate versions. I've raise HHH-13432 to see if the Hibernate team agree. I'll close this issue for now, but if it turns out to be a bug on our side we'll reopen it.

@philwebb philwebb added for: external-project For an external project and not something we can fix and removed status: waiting-for-triage An issue we've not yet triaged labels Jun 10, 2019
@philwebb philwebb reopened this Sep 23, 2019
@philwebb philwebb added type: bug A general bug and removed for: external-project For an external project and not something we can fix labels Sep 23, 2019
@philwebb philwebb added this to the 2.2.x milestone Sep 23, 2019
@philwebb
Copy link
Member

Turns out we're relying on something that isn't defined in the spec

I’m not aware that the spec says this should be supported (accessing “config settings” defined outside its properties block). It is not tested in the TCK.

I think the Hibernate team are going to change their code, but we should also look if there's something we can do locally.

@philwebb philwebb modified the milestones: 2.2.x, 2.1.x Sep 25, 2019
@philwebb philwebb changed the title DataSourceInitializedEvent picks wrong datasource in spring boot 2.1.x DataSourceInitializedEvent picks wrong datasource Sep 26, 2019
@philwebb philwebb modified the milestones: 2.1.x, 2.1.9 Sep 26, 2019
@philwebb
Copy link
Member

We're unfortunately very light on tests for DataSourceInitializedPublisher but the I tried the sample application with the fix and it appears to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants