Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grails - Multiple Datasources

First, let me start that I have looked so many sites about the "correct" way to configure multiple datasource on Grails, every one of them (with Grails 2.0 and later) pointing to the docs , however after doing what the docs says I get this error:

Error 2014-03-29 15:48:29,219 [localhost-startStop-1] ERROR context.GrailsContextLoader      - Error initializing the application: Error creating bean with name 'transactionManager_lookup': Cannot resolve reference to bean 'sessionFactory_lookup' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory_lookup': Cannot resolve reference to bean 'transactionManager' while setting bean property 'transactionManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean '$primaryTransactionManager' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '$primaryTransactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Cannot resolve reference to bean 'transactionManager' while setting bean property 'transactionManager'; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'transactionManager': Requested bean is currently in creation: Is there an unresolvable circular reference?
Message: Error creating bean with name 'transactionManager_lookup': Cannot resolve reference to bean 'sessionFactory_lookup' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory_lookup': Cannot resolve reference to bean 'transactionManager' while setting bean property 'transactionManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean '$primaryTransactionManager' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '$primaryTransactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Cannot resolve reference to bean 'transactionManager' while setting bean property 'transactionManager'; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'transactionManager': Requested bean is currently in creation: Is there an unresolvable   circular reference?

What I find most interesting is that if I specify:

dataSource_lookup

I will get:

Error initializing the application: Error creating bean with name     'transactionManager_lookup'

And if I change it to:

dataSource_mysqldb

I get:

Error initializing the application: Error creating bean with name 'transactionManager_mysqldb'

If I don't specify a second datasource, everything works just fine.

My code:

dataSource {
 logSql = true
 pooled = true
 dialect = org.hibernate.dialect.MySQLInnoDBDialect
 driverClassName = 'com.mysql.jdbc.Driver'
 username = 'myuser'
 password = 'mypass'
 url = 'jdbc:mysql://localhost/mydatabase'
 dbCreate = 'update'
}

dataSource_mysql {
 dialect = org.hibernate.dialect.MySQLInnoDBDialect
 driverClassName = 'com.mysql.jdbc.Driver'
 username = 'myuser'
 password = 'mypass'
 url = 'jdbc:mysql://localhost/mydatabase'
 dbCreate = 'update'
}

dataSource_oracle {
 dialect = org.hibernate.dialect.Oracle10gDialect
 driverClassName = 'oracle.jdbc.driver.OracleDriver'
 username = 'myuser'
 password = 'mypass'
 url = 'jdbc:oracle:thin:@localhost:1521:mydatabase'
 dbCreate = 'update'
}

What am I doing wrong here? (As stated before, if I eliminate the two secondary dataSources (dataSource_mysql and dataSource_oracle) everything works just fine).

Thanks in advance. Dev: Ubuntu - Grails 2.3.7 - MySQL - Oracle 11g.

like image 763
Alex Vargas Avatar asked Mar 29 '14 22:03

Alex Vargas


1 Answers

Ok I figured this out.

In the Grails 2.3.7 release notes it says to upgrade your hibernate version. I failed to do that.

http://grails.org/2.3.7+Release+Notes

runtime ':hibernate:3.6.10.10'

Then after I did that I stopped getting that error and got another error

java.lang.ClassNotFoundException: null at java.net.URLClassLoader$1.run(URLClassLoader.java:366) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:425) at ....MigrationUtils.createInstance(MigrationUtils.groovy:220) at ....MigrationUtils.getDatabase(MigrationUtils.groovy:57) at ....MigrationUtils.getDatabase(MigrationUtils.groovy:116) at DbmGenerateGormChangelog$_...doCall(DbmGenerateGormChangelog:52) at ....MigrationUtils.executeInSession(MigrationUtils.groovy:132) at DbmGenerateGormChangelog$_run_closure2.doCall(DbmGenerateGormChangelog:51) at DbmGenerateGormChangelog$_run_closure1.doCall(DbmGenerateGormChangelog:33)

I've never had to specify the hibernate dialect for oracle before, but apparently in the most recent version of the migrations plugin (1.3.8 currently), you have to.

dialect = "org.hibernate.dialect.Oracle10gDialect"

I was already specifying the dialect for MySQL so I don't know if it would produce the same error if removed.

like image 66
James Kleeh Avatar answered Sep 29 '22 01:09

James Kleeh