title: Hibernate One to One mapping. Insert only foreign key rather than whole new row
body: <p>I have RECEIPE table and CUISINE_ID is a foreign key of CUISINE.ID table. Is is possible while inserting new RECIPE, only CUISINE_ID is inserted and no new row in the CUISINE table.</p>
  
  <p>Table structure</p>
  
  <pre><code>create table CUISINE(cuisine_id number primary key, name varchar2(20));
  
  create table RECIPE(id number primary key,
                      name varchar2(25) not null,
                      cuisine_id number,
                      constraint cuisine_fk foreign key (cuisine_id) references
                      cuisine(cuisine_id));
  </code></pre>
  
  <p>Class mapping:</p>
  
  <pre><code>@Entity
  @Table(name = "cuisine")
  public class Cuisine {
      @Id
      @Column(name = "cuisine_id")
      private int id;
  
      @Column(name = "name")
      @NotBlank(message = "You can not leave this empty.")
      @NotNull(message = "You can not leave this empty.")
      private String name;
  
  
  @Entity
  @Table(name = "recipe")
  public class Recipe {
      @Id
      @Column(name = "id")
      private int id;
  
      @Column(name = "name")
      private String name;
  
      @OneToOne(cascade = CascadeType.ALL)
      @JoinColumn(name = "cuisine_id")
      private Cuisine cuisine;
  </code></pre>
  
  <p>Once I get RECEIPE class being populated from JSP page, I get following from the modelAttribute</p>
  
  <pre><code>Recipe [id=0, name=Burger, cuisine=Cuisine [id=0, name=American]
  </code></pre>
  
  <p>The DAO code is</p>
  
  <pre><code>public void addRecipe(Recipe recipe) {
          String hql = "select max(id) from Recipe";
          Integer id = ((Integer) getSession().createQuery(hql).uniqueResult()) + 1;
  
          recipe.setId(id);
          getSession().save(recipe);
      }
  </code></pre>
  
  <p>From logs I can see following is getting inserted:</p>
  
  <pre><code>Hibernate: insert into cuisine (name, cuisine_id) values (?, ?)
  Hibernate: insert into recipe (cuisine_id, name, id) values (?, ?, ?)
  </code></pre>
  
  <p>My requirement is no new row is inserted in cuisine table as recipe.cusinie_id should store id only.</p>
  
  <p>Thanks in advance,</p>