Please refer to my other blog titled “Configuring Multiple datasources in Grails” to know how to configure multiple datasources in Grails application. Now here I am writing about how to make finders work with multiple datasources in Grails. Lets say there is a domain called User which looks like :
1 2 3 4 5 6 7 8 9 10 11 |
[php] class User { String username String password boolean enabled boolean accountExpired boolean accountLocked static mapping = { datasource 'ALL' } [/php] |
Note : On line number 8 we mapped User domain with all datasources. Now we can find the user’s data from all datasources by Querying like:
1 2 3 4 5 |
[php] def userClass = User.class User user = userClass.master.findByName('amit') //Note : userclass.datasourceName.finder [/php] |
Hope this help some one..
Recent Comments