Reputation: 1129
In my grails 2 application I have multiple datasources configured in Datasources.groovy. My domain class mappings specify that all datasources should be used
class Book {
static mapping = { datasource 'ALL' }
For basic Gorm calls I am able to specify which datasource to use.
Book.lookup.save()
correctly uses the 'lookup' datasource
Is there a way to specify which datasource a criteria should use?
I have tried the following 4 solutions without any luck
def c = Book.lookup.createCriteria(); c.list{...
The call to .list throws: java.sql.SQLException: Connection is closed
def c = Book.createCriteria(); c.lookup.list{...
no such method
Injecting the datasource
def dataSource_lookup
...
Book.createCriteria(dataSource_lookup)
no such method
Specifying that the whole service where the criteria is located should use a specific datasource doesn't seem to be working for the criteria nor for the basic save() call. I'm running grails 2.1.0.
static datasource = 'lookup'
Upvotes: 2
Views: 1091
Reputation: 1129
Not a great solution, however it does work if you access the datasource beforehand (presumably within the same hibernate session).
Book.lookup.read(1)
def c = Book.lookup.createCriteria()
c.list{...
Upvotes: 1