title: JPA / Hibernate OneToOne Null in foreign key
body: <p>I have the following two entities with a bi-directional OneToOne relational mapping, data access is provided by Hibernate EntityManager v. "3.5.1-Final".</p>
  
  <pre><code>@Entity
  @Table(name = "details")
  public class Details {
      private Long id;
      private User user;
  
      public void setUser(User user) {
          this.user = user;
      }
  
      @OneToOne  
      @JoinColumn(name="user_id") 
      public User getUser() {
          return user;
      }
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Column(name = "id", unique = true, nullable = false)
      public Long getId() {
          return id;
      }
  
      private void setId(Long id) {
          this.id = id;
      }
  }
  </code></pre>
  
  <p>And:</p>
  
  <pre><code>@Entity
  @Table(name = "users")
  public class User {
  private Long id;
  private Details details;
  
  public void setDetails(Details details) {
      this.details = details;
  }
  
  @OneToOne(mappedBy="user",cascade=CascadeType.ALL)  
  public Details getDetails() {
      return details;
  }
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Column(name = "id", unique = true, nullable = false)
      public Long getId() {
          return id;
      }
  
      private void setId(Long id) {
          this.id = id;
      }
  }
  </code></pre>
  
  <p>Persistence code:</p>
  
  <pre><code>User user = new User();
  Details details = new Details();
  user.setDetails(details);
  
  entityManager.persist(user);
  </code></pre>
  
  <p>Data is then inserted correctly in both tables, the problem is that FK in details table "user_id" gets null, not sure whats missing here.</p>