Spring JPA Hibernate object null when saving ManyToOne
<p>I have got two entities in bidirectional relation ( ManyToOne, OneToMany )
Two tables House &amp; Room. House has many rooms.<br>
I need to save house with it's address and two ( maybe later on more ) rooms.
The below code adds house and address without rooms ( room = null ).</p>

<p>How can I achieve this?</p>

<p>Does my inputs concerning rooms are ok? e.g in PHP I'll have 
<code>name="roomName[]"</code></p>

<p>I thought that Hibernate will do everything for me :) especially when I use cascadeType.ALL</p>

<pre><code>@Entity
@Data
public class House {

  @Id
  @GeneratedValue(strategy = IDENTITY)
  private Long id;

  private String name;

  @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
  @JoinColumn(name = "address_id")
  private PostalAddress address;

  @OneToMany(cascade = CascadeType.ALL, mappedBy = "house", fetch = FetchType.EAGER)
  private Set&lt;Room&gt; rooms;
}
</code></pre>

<p><strong>Room</strong></p>

<pre><code>@Entity
@Data
public class Room {

  @Id
  @GeneratedValue(strategy = IDENTITY)
  private int id;

  private String name;

  @NotNull
  private int capacity;

  @NotNull
  @ManyToOne
  @JoinColumn(name = "house_id")
  private House house;
}
</code></pre>

<p><strong>Create db entry Form</strong></p>

<pre><code>&lt;input type="text" name="name" placeholder="house name..." /&gt;
&lt;input type="text" name="address.addressLocality" placeholder="locality" /&gt;
&lt;input type="text" name="address.postalCode" placeholder="postalCode" /&gt;
&lt;input type="text" name="address.streetAddress" placeholder="street" /&gt;
&lt;input type="text" name="room.name" placeholder="room name" /&gt;
&lt;input type="text" name="room.capacity" placeholder="capacity" /&gt;
&lt;input type="text" name="room.name" placeholder="room name" /&gt;
&lt;input type="text" name="room.capacity" placeholder="capacity" /&gt;
</code></pre>

<p><strong>Finally my Controller and repository</strong></p>

<pre><code>public interface RoomRepository extends CrudRepository&lt;Room, Long&gt; {
}

@RequestMapping(value = "/create", method = RequestMethod.POST)
public String saveHouse(@ModelAttribute("house/new") House house, BindingResult bindingResult, Model model) {

  houseRepository.save(house);

  return "redirect:/house/list";

}
</code></pre>

<p>// IMPORTANT EDIT</p>

<p>I've got tip what can be wrong but I can't resolve this. I'm using Thymeleaf. When House has Many Rooms ( Set rooms ) the part of the form that contains room inputs is incorrect. I'm displaying, by default, 4 rows ( room name, capacity ) in table</p>

<pre><code>&lt;tr th:each="i,iterStat : ${#numbers.sequence( 1, 4)}"&gt;
   &lt;td class="col-xs-9 col-md-9"&gt;&lt;input type="text" name="rooms.name" th:value="ROOM + ' ' + ${iterStat.current}"  class="form-control"/&gt; &lt;/td&gt;
   &lt;td class="col-xs-2 col-md-2"&gt;&lt;input type="number" name="rooms.capacity" min="1" step="1" value="4" class="form-control"/&gt; &lt;/td&gt;
   &lt;td class="col-xs-1 col-md-1"&gt;&lt;button type="button" class="btn red pull-right" onclick="removeTableRow(this)"&gt; &lt;i class="fa fa-trash"&gt;&lt;/i&gt; &lt;/button&gt;&lt;/td&gt;
&lt;/tr&gt;
</code></pre>

<p>when user would like to add more or less rooms he ( using jQuery ) deletes/add table row with inputs
I was trying to change input name to</p>

<blockquote>
  <p>th:field="*{rooms[<strong>${iterStat.current}</strong>].name}"</p>
</blockquote>

<p>but this is not it. So how to populate these fields?</p>