JPA Persist parent and child with one to many relationship
<p>I want to persist parent entity with 20 child entities, 
my code is below</p>

<p>Parent Class</p>

<pre><code>@OneToMany(mappedBy = "parentId")
private Collection&lt;Child&gt; childCollection;
</code></pre>

<hr>

<p>Child Class</p>

<pre><code>@JoinColumn(name = "parent_id", referencedColumnName = "parent_id")
@ManyToOne(optional=false)
private Parent parent;
</code></pre>

<hr>

<pre><code>String jsonString = "json string containing parent properties and child  collection" 

ObjectMapper mapper = new ObjectMapper();
Parent parent = mapper.readValue(jsonString, Parent.class);

public void save(Parent parent) {
    Collection&lt;Child&gt; childCollection = new ArrayList&lt;&gt;() ;

    for(Child tha : parent.getChildCollection()) { 
        tha.setParent(parent);
        childCollection.add(tha);
    }

    parent.setChildCollection(childCollection);
    getEntityManager().persist(parent);
 }
</code></pre>

<p>So if there are 20 child tables then I have to set parent reference in each of them for that I have to write 20 for loops?
 Is it feasible? is there any other way or configuration where I can automatically persist parent and child?</p>