title: OneToOne Mapping - Play Framework Entity
body: <p>I'm struggling to successfully implement a OneToOne mapping on my play framework application.</p>
  
  <p>examples I have are:</p>
  
  <pre><code>@Entity
    public class Profile extends GenericModel {
    @Id
    @GeneratedValue(generator = "foreignGenerator")
    @GenericGenerator(name = "foreignGenerator", strategy = "foreign", 
              parameters = @Parameter(name = "property", value = "user"))
    public static int id;
  
    @OneToOne(mappedBy="profile",  cascade = {CascadeType.ALL})
    public static User user;
  }
  </code></pre>
  
  <p>and :</p>
  
  <pre><code>@Entity
    public class User extends Model {
  
    @Required
    public String firstName;
  
    @Required
    public String surname;
   }
  </code></pre>
  
  <p>in this setup it throws: </p>
  
  <blockquote>
    <p>org.hibernate.AnnotationException: No identifier specified for entity: models.Profile</p>
  </blockquote>
  
  <p><strong>EDIT</strong>: As per <a href="https://stackoverflow.com/a/8561232/444991">Christian Boariu's answer</a>, I have modified Profile to what you have suggested and User to:</p>
  
  <pre><code>    @Entity
    public class User extends GenericModel {
  
  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  public Long user_id;
  
  @Required
  public String firstName;
  
  @Required
  public String surname;
  
  @OneToOne(cascade = {CascadeType.ALL})
  @PrimaryKeyJoinColumn(name = "user_id", referencedColumnName = "profile_id")
  public Profile profile;
  
  public Profile getProfile() {
      return profile;
  }
  
  public void setProfile(Profile profile) {
      this.profile = profile;
  }   
   }
  </code></pre>
  
  <p>Also added getter/setter to Profile:</p>
  
  <pre><code>public User getUser() {
      return user;
  }
  
  public void setUser(User user) {
      this.user = user;
  }
  </code></pre>
  
  <p>But I am now getting <code>hibernate.id.IdentifierGenerationException: null id generated for:class models.Profile</code>.. not sure how to correct?</p>