title: How do Hibernate/JPA persist objects in side another object?
body: <p>I have three classes (House, Room, Address) which are persistent (Mapped with JPA/Hibernate)   </p>
  
  <pre><code>@Entity
  @Table(name = "HOUSE")    
  @AttributeOverrides({@AttributeOverride(name = "house_id", column = @Column(name =     "house_id"))})
    public class House{
  
  
       @Basic     
       private String key;
       @OneToMany(mappedBy = "house", cascade = {CascadeType.ALL},    orphanRemoval = true)
       private List&lt;Room&gt; rooms;
  
          @OneToOne(fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST})
          @JoinColumn(name = "add_id")
          private Address address;
  }
  
   public static void main(String args){
   String key="key1";
   Room room1=...
   Room room2=...
   List&lt;Room&gt; rooms=//add the two rooms
   .
   .
   House house= new House(key, rooms, address);
  
   // Here is my question.
   // Now I call the save method on the persistent class
  
    house.save();
  }
  </code></pre>
  
  <p>1) Are Address and Room objects going to be persisted automatically or should I have to call  save method on each of them (<code>room1.save()</code>, <code>room2.save()</code>, <code>address.save()</code>) before calling <code>house.save()</code>? How about when I delete the house obj?</p>
  
  <p>2) The class "house" is the top of the hierarchy. I understood that if we call the save on the owning entity, it will persist the room and address as well. How about the reverse? If I edited the room, how do I make sure that the "house" knows about it?</p>