I have 2 entities : Account and AccountRole.
public class Account {
private AccountRole accountRole;
@ManyToOne(cascade = Ca
Just replace the
entityManager.persist(account);
with:
entityManager.merge(account);
And allow merge cascading:
@ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE }, fetch = FetchType.EAGER)
public AccountRole getAccountRole() {
return accountRole;
}
Because merge does this:
If your entity is new, it's the same as a persist(). But if your entity already exists, it will update it.