jpa hibernate one-to-one update
<p>I'm working on an apartment management software and I'm having an issue.</p>

<p>There is two entities I have :</p>

<pre><code>@Entity
public class Tenant extends AbstractEntity { //AbstractEntity contains the id
    @Column(nullable = false)
    private int number;
    @OneToOne
    private Apartment apartment;
}
</code></pre>

<p>and</p>

<pre><code>@Entity
public class Apartment extends AbstractEntity { //AbstractEntity contains the id
    @Column(nullable = false)
    private int number;
    @OneToOne
    private Tenant tenant;
}
</code></pre>

<p>But when I do </p>

<pre><code>EntityManager em = emProvider.get();
em.getTransaction().begin();

em.merge(apartment);
em.flush();

em.getTransaction().commit();
</code></pre>

<p>It only save the Tenant into the Apartment but I would like it also update the Apartment into the Tenant.</p>

<p>Do I really need to set the apartment field into the tenant or there is a way to fix it simply?
Thanks</p>

<p>Cordially,
Baskwo</p>