title: How do I create a composite primary key in hibernate within the hbm.xml file
body: <p>I have the following three simple classes.
  How do I go about mapping the Rating class and more specifically its composite key in my Rating.hbm.xml file?
  I'm currently getting quite lost in the hibernate documentation (5.1.2.1. Composite identifiers)</p>
  
  <p>Each rating can have one book and one user making that specific rating.
  Each user can make many ratings.
  Each book can have many ratings.</p>
  
  <p>Classes</p>
  
  <p>Rating class</p>
  
  <pre><code>    public class Rating {
          private User user;
          private Book book;
          private int rating;
          private Date timestamp;
  
          public Rating() {}  //No arg contructor for hibernate
      ... 
  }
  </code></pre>
  
  <p>User class</p>
  
  <pre><code>public class User {
      private long userId;
      private String email, password;
      public User() {}
      ...
  }
  </code></pre>
  
  <p>Book class</p>
  
  <pre><code>public class Book {
      private long bookId;
      private String title;
  
      public Book() {}
      ...
  }
  </code></pre>