I am trying to update the child entities using entity manager merge().My entities are:
@Entity
public class Customer {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
private String name;
@OneToMany(cascade = {CascadeType.ALL}, fetch = FetchType.EAGER, mappedBy = "customer")
private Set<Address> stores = new LinkedHashSet<>();
}
@Entity
public class Address{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
private String addressType;
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "customerId")
private Customer customer;
}
I add Address(child entities) in one jsp page and removes them in another jsp page and saving it using entity manager merge method and in each page i am saving the customer( parent entity). It works perfectly until adding addresses but after removal its not removing the address related to customer . Please have a look and let me know whether iam missing anything.