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

Grails 3.3 (hibernate plugin) dataSource bean is populated after the HibernateDatastore #10769

Closed
saw303 opened this issue Aug 9, 2017 · 2 comments
Assignees
Milestone

Comments

@saw303
Copy link
Contributor

saw303 commented Aug 9, 2017

I am trying to declare a Flyway Spring bean that get initialized just before Hibernate starts to validate the underlying database schema in order to apply database migration scripts.

Expected behaviour

Here is what I like to do. I want to register Flyway as a Spring bean and inject the dataSource into it. In order to have Flyway run its db migrations before Hibernate starts to validate the underlying database schema I add the flyway bean as a dependency onto the hibernateDatastore bean. The expected bean creation order should then be as follows:

  1. dataSource
  2. flyway
  3. hibernateDatastore

Actual behaviour

The problem is that the Grails Hibernate plugin defines first a bean called hibernateDatastore. This is triggering Hibernate to validate the underlying database schema. After creating the hibernateDatastore the plugin tells Spring to execute the BeanDefinitionRegistryPostProcessor of org.grails.orm.hibernate.support.HibernateDatastoreConnectionSourcesRegistrar registers a dataSource bean. For my use case this should be the other way around as it was in previous versions of Grails.

The following question at Stackoverflow provides further code listings that were running in Grails <= 3.2.x

@saw303
Copy link
Contributor Author

saw303 commented Aug 9, 2017

Maybe related to #10760

@graemerocher
Copy link
Member

#10760 is unrelated

Previous versions of Grails created the dataSource bean separately from the session factory. We would need to restore this behaviour I guess so the dataSource can be referenced without triggering the creation of the sessionFactory

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants