grails-database-migration
grails-database-migration copied to clipboard
SessionFactory bean has another name as expected
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
+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
just hit this one as well. pull-request targeting 3.0.x
coming up.
there it is: #164