title: Hibernate - Is there a way to join 2 columns against 1?
body: <p>I'm developing webapp using Spring &amp; Hibernate. </p>
  
  <p>Table 1: BaseTable</p>
  
  <pre><code>+------------+--------------+------+-----+---------+----------------+
  | Field      | Type         | Null | Key | Default | Extra          |
  +------------+--------------+------+-----+---------+----------------+
  | Id         | bigint(20)   | NO   | PRI |         | auto_increment |
  | Serial1    | varchar(255) | YES  |     | NULL    |                |
  | Serial2    | varchar(255) | YES  |     | NULL    |                |
  | ModelNum   | varchar(255) | YES  |     | NULL    |                |
  | ...        | ....         | ..   | 0   |         |                |
  +------------+--------------+------+-----+---------+----------------+ 
  </code></pre>
  
  <p>Table 2: DetailTable </p>
  
  <pre><code>+------------+--------------+------+-----+---------+----------------+
  | Field      | Type         | Null | Key | Default | Extra          |
  +------------+--------------+------+-----+---------+----------------+
  | Id1        | varchar(20)  | NO   | PRI |         |                |
  | Id2        | varchar(20)  | NO   | PRI |         |                |
  | Id3        | varchar(20)  | NO   | PRI |         |                |
  | Serial     | varchar(255) | YES  |     | NULL    |                |
  | ...        | ....         | ..   | 0   |         |                |
  +------------+--------------+------+-----+---------+----------------+
  </code></pre>
  
  <p>I need join the tables based on serials. The <code>Serial</code> in <code>Table2</code> may contain values from either <code>Serial1</code> or <code>Serial2</code> from <code>Table1</code> so it should compare like an OR operator. I'm using hbm.xml for tables. No annotation mapping. I've joined tables like: </p>
  
  <pre><code>&lt;one-to-one name="notes"
      class="Notes" entity-name="Notes"&gt;
  &lt;/one-to-one&gt;
  </code></pre>
  
  <p>I was using this Query before:</p>
  
  <pre><code>SELECT A.* FROM Table2 As a INNER JOIN Table1 As b 
  ON (a.Serial = b.Serial1 or a.Serial = b.Serial2);
  </code></pre>
  
  <p>I went through this <a href="http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/associations.html">http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/associations.html</a> but only 1 key column is being used. </p>
  
  <p>How do I join using HBM.XML for this scenario? Is it possible?</p>