title: Relational Mapping between tables in different schema
body: <p>Currently application is working on multiple schema in database, so we have a common schema that stores master tables whereas other schemas where we store client specific data.</p>
  
  <p>So, specific scenario is like </p>
  
  <p>(Below tables are for example purpose)</p>
  
  <p>Master table for <code>AnimalType</code> which is resided in <code>common</code> schema whereas <code>Animal</code> table which is available on all client schema such as <code>schema1</code>, <code>schema2</code>...<code>schemaN</code>.</p>
  
  <p>We are using <code>Grails</code> which default uses <code>Hibernate</code> so, relation is like </p>
  
  <pre><code>class AnimalType {
     String type
  
     static mapping = {
       datasources(['index'])
     }
  }
  
  class Animal {
     String name
     AniamlType animalType
  
  }
  </code></pre>
  
  <p>So, when I start the application it shows below exception:</p>
  
  <blockquote>
    <p>Caused by: org.springframework.beans.factory.BeanCreationException:
    Error creating bean with name 'sessionFactory': Invocation of init
    method failed; nested exception is org.hibernate.MappingException: An
    association from the table animal refers to an unmapped class:
    org.sample.AnimalType</p>
  </blockquote>
  
  <p>What I understood from this is because, <code>Animal</code> is trying to refer to <code>AnimalType</code> in it's own schema, but <code>AnimalType</code> does not exists there.</p>
  
  <p>So, basically I want to map <code>Animal</code> to <code>AnimalType</code> pointing to <code>common</code> schema.</p>
  
  <p>Something like below with syntax in Grails</p>
  
  <pre><code>class Animal {
     String name
  
     @(POINTING TO COMMON SCHEMA)
     AnimalType animalType
  }
  </code></pre>