title: Hibernate class with primary key that is also a foreign key
body: <pre><code>@Entity
  @Table(name = "USER_DATA")
  public class UserData {
      Entity entity;
  
      @OneToOne(fetch = FetchType.EAGER)
      @PrimaryKeyJoinColumn(name="PK_FK_ENTITY")
      @Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE})
      public Entity getEntity() {
          return entity;
      }
  
      public void setEntity(Entity entity) {
          this.entity = entity;
      }
  }
  </code></pre>
  
  <p>Error given is "No identifier specified for entity". How can I specify that the entity field is both a primary and a foreign key? Note that there is no class hierarchy for 'UserData' here; it is just a single class. It just so happens that for every 'UserData' there will only be one 'Entity', hence we want to make it both a primary and a foreign key.</p>