Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6933465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:50:09+00:00 2026-05-27T11:50:09+00:00

I have a situation where I need to connect multiple DBs to get all

  • 0

I have a situation where I need to connect multiple DBs to get all the attributes for a single object (poor legacy design). I followed the instructions at http://grails.org/doc/2.0.0.RC1/guide/conf.html#multipleDatasources to hook up the 2nd database, but now I’m a bit stumped on how to map it to my class — telling it which columns come from which tables in which DB.

My primary source is called dataSource, and my secondary is called dataSource_cvs as the instructions in the documentation recommended. (Upon inspection, I see that this section has since been removed from the latest grails documentation at http://grails.org/doc/latest/guide/3.%20Configuration.html)

I’m now wondering what the next step is. I want to know how I can specify using annotations or GORM that the different attributes are being mapped from different DBs, and bring them together. Also, do I have to do anything funny in my hibernate.cfg.xml, such as a separate session-factory for the 2nd database? If so, do I just need to add the mapping class to both session-factories?

Thanks!

ETA: If it helps, the 2nd database (hooked to cvs) only has to be read-only for this particular situation.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T11:50:10+00:00Added an answer on May 27, 2026 at 11:50 am

    As far as I understand it, you can’t map individual domain class properties to multiple data sources. You would have to create two domain classes: one that maps to the read-write database and another than maps to the read-only one. Then set up a relationship between the two.

    For convenience in your coding, you could add transient read-only properties to your main domain class:

    class ReadWrite {
        ...
        static hasOne = [readOnly: ReadOnly]
    
        static transients = ["name"]
    
        static mapping = {
            readOnly fetch: "join"
        }
    
        String getName() {
            return readOnly.name
        }
    }
    

    Note that I’ve made the readOnly property eager so that you don’t have a second query every time you access the getName() method for the first time in a session.

    Whether this is an efficient approach is another question, but I’ll leave that to others.

    BTW the section on multiple data sources hasn’t been removed from the user guide. ‘latest’ is currently pointing at the 1.3.7 user guide whereas multiple data source support in core is specific to Grails 2.0. Very soon, ‘latest’ will point to the 2.0 user guide…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's the situation: we have an Oracle database we need to connect to to
I have a situation where I need the Checker enum below used in multiple
I have a situation where I need multiple renders to occur with the same
I have situation where I need to change the order of the columns/adding new
I have a situation where I need to be able to load assemblies in
I have a situation where I need to work with a datagrid and adding
I have a situation where i need to debug a Windows CE application in
I have a situation where I need to add an arbitrary unique id to
I have a situation where I need to do something like select 2, id
I have a situation where i need to enforce a unique constraint on a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.