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

SessionFactory bean has another name as expected #157

Open
vdusa opened this issue May 20, 2019 · 2 comments
Open

SessionFactory bean has another name as expected #157

vdusa opened this issue May 20, 2019 · 2 comments

Comments

@vdusa
Copy link

vdusa commented May 20, 2019

When multiple data sources are used, then dbm-gorm-diff, dbm-generate-changelog, etc. fail for the non default data sources:

For example:
We have default data source and 'another' data source in our application.yml

Running:
dbm-gorm-diff --dataSource=another
Fails with:
No bean named 'sessionFactory_dataSource_another' available

Cause:
No bean named sessionFactory_dataSource_another is registered. But list of registered beans contains sessionFactory_another.

Workaround:
We added

beans = {
	springConfig.addAlias('sessionFactory_dataSource_another', 'sessionFactory_another')
}

into grails-app/conf/spring/resources.groovy

  • Operating System: Windows 10
  • Grails Version: 3.3.9
  • Plugin Version: org.grails.plugins:database-migration:3.0.4, org.liquibase:liquibase-core:3.5.5
  • Database: MySQL
  • JDK Version: AdoptOpenJDK jdk8u202-b08
@AntonPanikov
Copy link

+1 the same issue
ApplicationContextDatabaseMigrationCommand.groovy

in both versions 3.0.4 and 3.1.0 is looking for session factory by concatinating "sessionFactory" and datasource bean name, not a datasource name:

        String dataSourceName = getDataSourceName(dataSource)
        String sessionFactoryName = "sessionFactory"
        if (!isDefaultDataSource(dataSource)) {
            sessionFactoryName = sessionFactoryName + '_' + dataSourceName
        }

so if your data source is "audit", then "getDataSourceName()" will return "dataSource_audit" as needed to get another bean, but session factory bean name will be "sessionFactory_audit", so it will fail to find "sessionFactory_dataSource_audit"

Also using Grails: 3.3.9 and database-migration:3.0.4

@zyro23
Copy link
Contributor

zyro23 commented Oct 31, 2019

just hit this one as well. pull-request targeting 3.0.x coming up.

there it is: #164

zyro23 added a commit to zyro23/grails-database-migration that referenced this issue Oct 31, 2019
when constructing the sessionFactory bean name for a secondary dataSource, just append the suffix, not the complete dataSource bean name (i.e. sessionFactory_another instead of sessionFactory_dataSource_another)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants