why hibernate not set foreign key in the owner side of OneToMany
<p>I have 2 Entities, Hospital and Department, Department reference its hospital by hospital_id in it.</p>

<pre><code>@Entity
public class Hospital {
    ...
    private Set&lt;Department&gt; departments;

    @OneToMany(mappedBy = "hospital", cascade = CascadeType.ALL)
    public Set&lt;Department&gt; getDepartments() {
        return departments;
    }
}

@Entity
public class Department {
    ...
    private Hospital hospital;

    @ManyToOne(cascade = CascadeType.ALL)
    @JoinColumn(name = "hospital_id")
    public Hospital getHospital() {
        return hospital;
    }
}
</code></pre>

<p>I use Rest API to create instance of Entities:</p>

<pre><code>@RequestMapping("/create")
@ResponseBody Hospital create(@RequestBody Hospital hospital){
    hospital = hospitalService.save(hospital);

    return hospital;
}
</code></pre>

<p>I post json payload to create a Hospital:</p>

<pre><code>{"name":"t-hospital", "departments":[{"name": "department1"}]}
</code></pre>

<p>Since I use SpringBoot, Jackson will auto parse the json payload into Java Object, here its Hospital and Departments in it.</p>

<p>While after I save the hospital, I found the foreign key: 'hospital_id' in department is not set.</p>

<p>Why is this and if possible, how can I make the foreign key set when I save the hospital object?</p>