title: Hibernate: need update parent entity without pulling all its child-cascade
body: <p>I faced the problem when I need to partially udate data in BD.</p>
  
  <p><strong>What I have:</strong>
  I have three linked entities:</p>
  
  <p><strong>Profile</strong> --<em>(1-m)</em>--> <strong>Person</strong> --<em>(1-1)</em>--> <strong>Address</strong></p>
  
  <p>Where Person -> Address is lazy relationship. It was achieved via optional=false option (that allow hibernate to use proxy).</p>
  
  <p><strong>What the problem:</strong></p>
  
  <p><em>I need to <strong>update Profile</strong> in such way, that I <strong>needn't pull all Addresses</strong> that linked with this profile.</em></p>
  
  <p>When I update Profile (<em>don't work</em>): </p>
  
  <pre><code>profile.setPersons(persons);
  session.saveOrUpdate(profile);
  </code></pre>
  
  <p><em>throws</em>: org.springframework.dao.DataIntegrityViolationException: not null property references a null or transient value</p>
  
  <p>It happens because Person->Address relationship has optional=false option</p>
  
  <p><em>I need to do:</em></p>
  
  <pre><code>//for each person
  Address address = requestAddressFromDB();
  person.setAddress(address);
  persons.add(person)
  //and only then
  profile.setPersons(persons);
  session.saveOrUpdate(profile);
  profile.setPerson(person)
  </code></pre>
  
  <p>But I don't want to pull all address each time I update Profile name.</p>
  
  <p><strong>What is the question:</strong></p>
  
  <p>How can I avoid obligatory Person->(not null)Address constraint to save my profile without pulling all addresses?</p>
  
  <p><strong>ADDITION</strong>:</p>
  
  <pre><code>@Entity
  public class Person{
  
    @Id
    @SequenceGenerator(name = "person_sequence", sequenceName = "sq_person")
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "person_sequence")
    @Column(name = "id")
    private long personID;
  
    @OneToOne(mappedBy="person", cascade=CascadeType.ALL, optional = false, fetch = FetchType.LAZY)
    private Address address;
    //.. getters, setters
  }
  
  @Entity
  public class Address {
  
    @Id
    @Column(name="id", unique=true, nullable=false)
    @GeneratedValue(generator="gen")
    @GenericGenerator(name="gen", strategy="foreign", parameters=@Parameter(name="property", value="person"))
    private long personID;
  
    @PrimaryKeyJoinColumn
    @OneToOne
    private FileInfo person;
  }
  </code></pre>