title: JPA: Foreign key which only one from composite key
body: <p>I'm having trouble getting a composite primary key and foreign keys working in JPA 2/Hibernate. I'm trying to create a simple scenario with A and B:</p>
  <pre><code>CREATE TABLE Customer(
      customer_id uuid,
      employee_id int,
      created_at timestamp with time zone DEFAULT now(),
      
      CONSTRAINT customer_id_employee_id_pkey PRIMARY KEY (customer_id, employee_id),
      CONSTRAINT fk_owner_owner_id FOREIGN KEY (customer_id)
          REFERENCES public.owner (id) MATCH SIMPLE
          ON UPDATE CASCADE
          ON DELETE CASCADE
  )
  </code></pre>
  <p>How should I create entity class ?</p>
  <p>I tried below</p>
  <pre><code>@EqualsAndHashCode
  @Data
  public class CustomerId implements Serializable {
      private UUID customerId;
      private Long employeeId;
  }
  
  
  @Data
  @Entity
  @IdClass(CustomerId.class)
  @Table(name = &quot;customer&quot;)
  public class Customer implements Serializable {
      private static final long serialVersionUID = -234295442215152987L;
  
      @Id
      @Column(name = &quot;customer_id&quot;)
      private UUID customerId;
  
      @Id
      @Column(name = &quot;employee_id&quot;)
      private Long employeeId;
  
      @CreationTimestamp
      @Column(name = &quot;created_at&quot;, insertable = false, updatable = false)
      private OffsetDateTime createdAt;
  }
  </code></pre>
  <p>But I am not sure in which class should I map customer_id which is a foreign key.
  Please help me</p>