Grails - Multiple Data Sources

First, let me start by looking at so many sites about the โ€œrightโ€ way to configure multiple data sources on Grails, each of them (with Grails 2.0 and later) pointing to docs , however after doing what the document 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 do not specify a second data source, everything will be very good.

My code is:

 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 mentioned earlier, if I delete two secondary data sources (dataSource_mysql and dataSource_oracle), everything works fine).

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

+6
source share
1 answer

Ok, I figured it out.

The Grails 2.3.7 release notes say that you are updating the sleep mode. I could not do this.

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

runtime ':hibernate:3.6.10.10'

Then, after that, I stopped this 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 have never had to specify a dialect of sleep mode for the oracle before, but apparently in the latest version of the migration plugin (1.3.8 at present) you need to.

 dialect = "org.hibernate.dialect.Oracle10gDialect" 

I already pointed out the dialect for MySQL, so I donโ€™t know if it will lead to the same error when deleting.

+4
source

All Articles