开发者

How to use single domain that maps to multiple databases in groovy and grails

开发者 https://www.devze.com 2023-02-16 17:06 出处:网络
I have table named \'employee\' which was exists in two databases with same columns. For this table related CURD operations i have created one Domain class which is configured in Datasources.groovy t

I have table named 'employee' which was exists in two databases with same columns.

For this table related CURD operations i have created one Domain class which is configured in Datasources.groovy to point to one of the db.

Now, my problem is, is there anyway to use this same single domain which can 开发者_StackOverflowbe pointed to both the databases so, that while executing GORM methos on that domain i will pass db name as parameter.

Thanks,

Pavan


I've never seen this done before and would be surprised if you could out of the box. Your options would be to override save() etc on your Domain class and do it manually to the second database after you call super(), or you could set up replication between your databases. The second option might be more desirable when it comes to data integrity.


I haven't tried this, but it sounds as you could solve your problem using the Grails Sharding plugin:

  • Grails Sharding Plugin
  • DZone Article: Sharding in Grails
0

精彩评论

暂无评论...
验证码 换一张
取 消