title: Hibernate: How to partially save composite objects?
body: <p>Imagine that you have a Person entity with a one to one relationship with an Account entity. When mapping this in hibernate, your Person class has a Account property. </p>
  
  <p>Now suppose that a web application sends Person objects that it wants to update, but the module that does this doesn't care about its nested Account objects (for now) and it can't be burdened with keeping track of these (since they are not particularly lightweight and thus the fetching is set to LAZY). </p>
  
  <p>For these reasons, you might set your Account property on Person to updatable=false, insertable=false so that if you send a Person with a null Account it won't cause the relationship to be deleted. So far so good, but what happens when you do wan't to update the Account property, how would you do it? Is there a way to bypass insertable/updatable?</p>
  
  <p>Thanks</p>
  
  <p><strong>UPDATE</strong>
  Added sample code (Also, I was talking about the entity Account, but then I began referring to it as User for some reason, corrected that as well)</p>
  
  <pre><code> @Entity
  @Table(name="person")
  public class Person  implements java.io.Serializable
  {
      //properties  
      private Integer id;
      private String Name;
      //... this class would have many properties
  
  
  
      /*Most of the time the frontend will send a Person object
        that has this property set to null even if it exists
       because the screen that handles this doesn't manage accounts
  
        There are other screens that will send that complete person object with
      its account, so the problem is how to save an incomplete person object
      without deleting the relationship
      */
  
      @OneToOne(fetch=FetchType.EAGER)
      @JoinColumn(name="idAccount", insertable=false, updatable=false)
      public Account getAccount()
      {
          return this.account;
      }
  
      public void setAccount(Account account)
      {
          this.account = account;
      }
  }
  
  @Entity
  @Table(name="account")
  public class Account implements java.io.Serializable
  {
      //properties
      private Integer idAccount;
      //this class has even more properties and nested objects
  }
  </code></pre>