How do you access two databases in Grails

后端 未结 6 1113
Happy的楠姐
Happy的楠姐 2020-12-30 00:29

Grails makes it very easy to configure datasources for different environments (development, test, production) in its DataSources.groovy file, but there seems to be no facili

6条回答
  •  我在风中等你
    2020-12-30 01:09

    The following post seems to be the best source of information on the subject:

    How to get mutli-dataSource in grails

    It boils down to:

    • Define datasource1 in DevelopmentDataSource
    • Define datasource2 in resources.xml
    • Write a DAO for CRUD of the domain objects using datasource2
    • In hibernate.cfg.xml, list all domain objects.

    Only the first datasource will have dynamic finder methods.

    If its a really simple query you are after and don't mind not having the ORM features you could use Groovy SQL or the native SQL features of Hibernate.

提交回复
热议问题