Grails makes it very easy to configure datasources for different environments (development, test, production) in its DataSources.groovy file, but there seems to be no facility for configuring multiple datasources in one environment. What to I do if I need to access several databases from the same Grails application?
+1
A:
The following post seems to be the best source of information on the subject:
How to get mutli-dataSource in grails
It boils down to:
- Define datasource1 in DevelopmentDataSource
- Define datasource2 in resources.xml
- Write a DAO for CRUD of the domain objects using datasource2
- In hibernate.cfg.xml, list all domain objects.
Only the first datasource will have dynamic finder methods.
If its a really simple qurey you are after and dont mind not having the ORM features you could use Groovy SQL or the native sql features of Hibernate.
Rich Lawrence
2008-09-04 08:01:27
+5
A:
There is now Grails plugin that enables the use of multiple datasources directly with Grails' GORM layer: http://burtbeckwith.com/blog/?p=70
Ben Williams
2008-09-08 18:27:50