title: Hibernate mapping multiple classes to one table using hbm.xml
body: <p>I am fairly new to Hibernate and need some help with hibernate-mapping.</p>
  
  <p>I have 4 different classes which I want to map into one table, of which the primary key consists of attributes from 2 different classes. At the same time, I want to map only selected attributes from each class into a local database. I wish to avoid JPA annotations and define the mapping style in a hbm.xml file instead. How do I do that?</p>
  
  <p>Take the following example:</p>
  
  <pre><code>public class Tenant implements Serializable {
      private final static long serialVersionUID = 1L;
      protected List&lt;Rack&gt; rack;
      protected String type;
      //getters setters
  }
  
  public class Rack implements Serializable {
      private final static long serialVersionUID = 1L;        
      protected List&lt;Circuit&gt; circuit;
      protected String rackLabel;
      protected Boolean excludes;
      //getters setters
  }
  
  public class Circuit implements Serializable {
      private final static long serialVersionUID = 1L;
      protected List&lt;CircuitReadings&gt; circuitReadings;
      protected String circuitNo;
      protected Boolean excludes;
      //getters setters
  }
  
  public class CircuitReadings
      implements Serializable {
      private final static long serialVersionUID = 1L;
      protected String date;
      protected String kva;
      protected String current;
      protected String kwh;
      //getters setters
  }
  </code></pre>
  
  <p>And the eventual table should consist of the following:    </p>
  
  <pre><code>    type | rackLabel | circuitNo | date | kva | current | energy
  </code></pre>
  
  <p>"circuitNo" and "date" above should form the composite primary keys.</p>
  
  <p>Can someone show me an example of how I should map this? Thanks!</p>