So if I want to do a direct SQL query using the session that Grails is using prior to supporting multiple datasources I could do:
def conn = new Sql(sessionFactory.currentSession.connection())
Now the question is that I have multiple datasources and want to grab a connection to a specific one.
How do I do that?
TIA
Better declare the data source in your bean (Service, Controller...) to be injected (no need to depend from Hibernate here)
and use it directly:
If you have multiple data sources, just follow the naming convention
Given a datasource defined in DataSource.groovy as "dataSource_foo", you'll have a
SessionFactory
calledsessionFactory_foo
. So you can dependency-inject it like any other Spring bean:and use it like this:
You can bind to the session using a Domain class reference as follows:
This method does not require a hardcoded reference to the datasource suffix.