Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

SessionFactory bean has another name as expected #973

Closed
vdusa opened this issue May 20, 2019 · 6 comments
Closed

SessionFactory bean has another name as expected #973

vdusa opened this issue May 20, 2019 · 6 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: grails/grails-database-migration#164

zyro23 referenced this issue in zyro23/grails-database-migration 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)
@jdaugherty jdaugherty transferred this issue from grails/grails-database-migration Feb 20, 2025
@jdaugherty
Copy link
Contributor

See grails/grails-database-migration#164 - this may still be an issue.

@zyro23
Copy link
Contributor

zyro23 commented Feb 20, 2025

thanks for the ping! just signed the cla for that pr - feel free to port to this repo (just saw the move).

@jdaugherty
Copy link
Contributor

@zyro23 would you have time to confirm this is still an issue in Grails 6 or Grails 7?

@zyro23
Copy link
Contributor

zyro23 commented Feb 20, 2025

yup, will take a look (9.0.x)

zyro23 added a commit to zyro23/gorm-hibernate5-973 that referenced this issue Feb 20, 2025
…7 (grails-database-migration-9.0.0-SNAPSHOT)
jdaugherty added a commit that referenced this issue Feb 20, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants