title: Composite id in Hibernate
body: <p>Good evening folks.</p>
  
  <p>I'm developing an application which uses Hibernate 4.x. I'm currently having problems while using a composite id in a class and, mapping a relation of another class to this one.</p>
  
  <p>I've got a ParadaBus object, which represent a Bus Stop (in Spanish) and each one is identified by a integer and a String:</p>
  
  <pre><code>public class ParadaBus implements Serializable {
  
     private Integer id;
     private String concesionRecogida;
  
     ......
  
     @Override
     public int hashCode() {
         return this.id.hashCode() + this.concesionRecogida.hashCode();
     }
  
     @Override
     public String toString() {
          return "ParadaBus [" + id + " " + concesionRecogida + "]";
     }
  }
  </code></pre>
  
  <p>On the other hand, I've got another class which holds a single instance of a ParadaBus object:</p>
  
  <pre><code>public class TrabajadorNombramiento implements Serializable {
      ...
     private ParadaBus suParada;
      ...
  }
  </code></pre>
  
  <p>I wanna map this relation with an XML HBM file, and I guess I'm doing incorrectly</p>
  
  <p>This is the .hbm.xml file for ParadaBus:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE hibernate-mapping PUBLIC 
      "Hibernate Mapping 3.0" 
      "http://hibernate.org/dtd/hibernate-mapping-3.0.dtd" &gt;
  &lt;hibernate-mapping&gt;
  
  &lt;class name="com.ingartek.cavwebapp.model.ParadaBus" table="ParadasBus"&gt;
  
      &lt;composite-id &gt;
          &lt;key-property name="id" type="integer"&gt;
              &lt;column name="id" /&gt;    
          &lt;/key-property&gt;
  
          &lt;key-property name="concesionRecogida" type="string"&gt;
              &lt;column name="concesion_recogida" /&gt;    
          &lt;/key-property&gt;
  
      &lt;/composite-id&gt;
      ...
  &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>Up here, everything seems right. The following snippet code represents the hbm.xml for the other class, where the relation to ParadaBus should be mapped:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE hibernate-mapping PUBLIC 
      "Hibernate Mapping 3.0" 
      "http://hibernate.org/dtd/hibernate-mapping-3.0.dtd" &gt;
  &lt;hibernate-mapping&gt;
  
      &lt;class name="com.ingartek.cavwebapp.model.TrabajadorNombramiento" table="nombramientos"&gt;
          ...
          &lt;many-to-one name="suParada" class="com.ingartek.cavwebapp.model.ParadaBus" cascade="none"&gt;
              &lt;column name="id_parada" /&gt;
              &lt;column name="concesion_recogida" /&gt;
          &lt;/many-to-one&gt;
          ...
      &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>Am I doing something wrong?</p>
  
  <p>Thanks for your help.</p>
  
  <p>EDIT: </p>
  
  <p>Eventually, I decided to use a UUID to identify each ParadaBus object/row.</p>