title: how to use two columns as primary key in hibernate
body: <p>I have a table with  five columns. The two columns, together, make up the primary key of my table. I'm trying to instantiate  an Entity class that corresponds to that table using hibernate. The problem is how do I tell hiberante that the primary key is not just a single field of the class but two. I don't want hiberante to create the database schema for me as I have already crated it with all the necessary primary key settings.</p>
  
  <p>I have read about the <strong>composite-key</strong> but it think that is not suitable for me. After all, I only have one table and there won't be one-to-many or similar cardinality in my code.</p>
  
  <p>I tried something like this which apparently ain't working. </p>
  
  <pre><code>    &lt;?xml version="1.0"?&gt;
      &lt;!DOCTYPE hibernate-mapping PUBLIC
      "-//Hibernate/Hibernate Mapping DTD//EN"
      "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"&gt;
      &lt;hibernate-mapping&gt;
         &lt;class name="blog.Message" table="MESSAGES"&gt;
         &lt;id name="title" column="MESSAGE_TITLE"&gt;&lt;/id&gt;
         &lt;id name="author" column="MESSAGE_AUTHOR"&gt;&lt;/id&gt;
         &lt;property name="body" column="MESSAGE_BODY"/&gt;
           // ....AND TWO MORE FIELDS
  
      &lt;/class&gt;
      &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>What is the way to do it? Is composite-key a must?
  Thanks in advance</p>