I have tried asking this in another question, but I may have put too many details.
I am using Grails and multiple datasources. If you want to use services to declare the datasource, that does NOT work at all for me.
static datasource = "db1"
No matter what, this has not worked for me in Grails Services
Thank you for any help/suggestions.
== I am editing this to include my Datasource.groovy
Now, this works fine if I use the static mapping on the domain object for my second database. However, I want the service to decide what database must be written to, therefore I was hoping that the service datasource attribute works as in the documentation.
If I declare that my domain object uses "ALL" datasources, the service will write to the default datasource, despite the fact that I set the
static datasource = "db21"
If I declare that my domain object uses "db1" datasource, the service will write to the db1 datasource
- If I declare 2,3...N datasources, it looks like the service will only write to the default datasource or the datasource I had declared in the domain groovy file. The documentation says I should be able to use services to choose the datasource.
=============== edit ==============
dataSource {
pooled = true
driverClassName = "org.h2.Driver"
username = "sa"
password = ""
}
hibernate {
cache.use_second_level_cache = true
cache.use_query_cache = true
cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory'
}
// environment specific settings
environments {
development {
dataSource {
dbCreate = "validate"
url = "jdbc:h2:devDb;MVCC=TRUE"
}
dataSource_db1 {
dbCreate = "validate"
url = "jdbc:h2:dev1Db;MVCC=TRUE"
pooled = true
driverClassName = "org.h2.Driver"
username = "sa"
password = ""
}
}
test {
dataSource {
dbCreate = "update"
url = "jdbc:h2:mem:testDb;MVCC=TRUE"
}
}
production {
dataSource {
dbCreate = "update"
url = "jdbc:h2:prodDb;MVCC=TRUE"
pooled = true
properties {
maxActive = -1
minEvictableIdleTimeMillis=1800000
timeBetweenEvictionRunsMillis=1800000
numTestsPerEvictionRun=3
testOnBorrow=true
testWhileIdle=true
testOnReturn=true
validationQuery="SELECT 1"
}
}
}
}