title: How to create a composite primary with JPA (or Hibernate) annotations
body: <p>I got this problem which is a very common problem and I decided to share the resolution here.</p>
  
  <p>The Problem:
  I have a composite primary key in one of my tables. I need to map this with JPA annotations.</p>
  
  <p>My POJO1:</p>
  
  <pre><code>public class Alarm {
  
      @Id
      @Column(name="alm_id")
      private String id;
  
      @Column(name="alm_description")
      private String desc;
  
      @ManyToOne
      @JoinColumn(name = "alm_norm_id")
      private Alarm normAlarm; 
  
      //getters and setters
  }
  </code></pre>
  
  <p>My POJO2:</p>
  
  <pre><code>public class Equipment {
  
      @Id
      @Column(name="equ_id")
      private String id;
  
      @Column(name="equ_fixed_asset")
      private String fixedAsset;
  
      @Column(name="equ_service_tag")
      private String serviceTag;
  
      //getters and setters
  
  }
  </code></pre>
  
  <p>So I have a table which the primary key is an <code>Equipment</code> + <code>Alarm</code> and I need to map that. </p>