title: Hibernate: Using two different DataBase schemas in the same application
body: <h2>Context</h2>
  
  <p>I'm creating a database environment where I'd like to split data in several different schemas to be used for different groups of users. Although, one of these databases should be shared to everyone due to it contains common entities.</p>
  
  <p>Suppose databases:</p>
  
  <ul>
  <li>DB1 - Common entities;
  <ul>
  <li>Wheels entity </li>
  </ul></li>
  <li>DB2 - Group "A";
  <ul>
  <li>Cars entity </li>
  </ul></li>
  <li>DB3 - Group "B";
  <ul>
  <li>Motorcycles entity</li>
  </ul></li>
  </ul>
  
  <p>I have three different projects:</p>
  
  <ul>
  <li>Project 1:
  <ul>
  <li>Wheels bean</li>
  </ul></li>
  <li>Project 2:
  <ul>
  <li>Cars constructor</li>
  </ul></li>
  <li>Project 3:
  <ul>
  <li>Motorcycles constructor</li>
  </ul></li>
  </ul>
  
  <h2>Problem</h2>
  
  <p>I'm trying to access wheels (Project 1) from projects/schemas (2,"A") and (3,"B")</p>
  
  <p>First question: Is it possible?
  Second: How can I do it?</p>
  
  <p><code>hibernate.cfg.xml</code> in project 2 is configured to </p>
  
  <pre><code>&lt;property name="hibernate.connection.url"&gt;jdbc:mysql://99.999.999.99:3306/DB2&lt;/property&gt;
  </code></pre>
  
  <p>This necessarily must restrict all the connections to DB2, or there's another way to add a new connection or work with all databases in 3306 port, or at least DB1?</p>
  
  <p>Mapping the entities from project1 <strong>in project 2</strong> seems not to be succeeded too, like:</p>
  
  <pre><code>&lt;mapping class="com.company.project1.Wheels"
          package="com.company.project1.Wheels" resource="com/company/project1/Wheels.hbm.xml"/&gt;
  </code></pre>
  
  <h2>Configuration</h2>
  
  <ul>
  <li>Eclipse Indigo</li>
  <li>MySql 5.5</li>
  <li>Hibernate 3.0 (mapping through xml instead annotations)</li>
  <li>Win 7</li>
  </ul>
  
  <p>Thanks for helping!</p>