When writing code in Spring for an array of objects, I have this code:

```
TaskList parent_list = repo.findOne(listId);

Task t = new Task();
// set fields for t

parent_list.getTasks().add(t);
repo.save(parent_list);

```

Here, `repo` is a repository of `TaskList`s, and is an extension of `JpaRepository` in Spring Data JPA.
`parent_list` contains some data about itself(name, owner) and a `List<Task>`.

My question is, before the call to `save()`, how is the add() function working? Why don't I need to return a value(i.e. need to do `parentList.setTasks(parent_list.getTasks().add(t));`)?

I am getting a null object as a result of the `repo.save()`.

I only have a repository for the `TaskList` object, not the `Task`. I was under the impression that there is no need for an extra repo; all you need is a relationship with the table from the first table and the entries are saved automatically.