I have two entities, for example:
Obs: Code fiction to facilitate understanding of the problem.
@Entity
public class Celular{
@Id
@GeneratedValue(strategy= GenerationType.IDENTITY)
private int id;
private String modelo;
@OneToMany(mappedBy = "celular")
private List<chamada> chamadas;
}
@Entity
public class Chamada{
@Id
@GeneratedValue(strategy= GenerationType.IDENTITY)
private int id;
@ManyToOne
@JoinColumn(name = "idcelular")
private Celular celular;
}
When changing the attribute of the Cell object, it is not reflected in the Call object. Example:
...
Chamada ch=celular.getChamada().get(0);
System.out.println(ch.getCelular().getModelo()); //imprime "NOKIA"
celular.setModelo("Motorola");
//persistir
getEntityManager().getTransaction().begin();
celular = getEntityManager().merge(entity);
getEntityManager().getTransaction().commit();
getEntityManager().close();
Chamada ch=celular.getChamada().get(0);
System.out.println(celular.getModelo()); //imprime "Motorola"
System.out.println(ch.getCelular().getModelo()); //imprime "Nokia"
What would be the correct procedure for the chamada
object to notice the change in celular
?