0

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.

user1188867
  • 3,726
  • 5
  • 43
  • 69
  • where is you merge code please – shareef Dec 02 '15 at 06:37
  • Its a simple call to merge method i will build customer from json using spring and iam sure that customer is building correctly. entityManager.merge(customer) – user1188867 Dec 02 '15 at 06:42
  • try `orphanRemoval=true` as specified in the docs - https://docs.oracle.com/cd/E19798-01/821-1841/giqxy/ – Omkar Puttagunta Dec 02 '15 at 10:24
  • Already tried it's not working – user1188867 Dec 02 '15 at 11:02
  • Check this mapping ` @JoinColumn(name = "customerId")` in `Address` class. Where is the`customerId` in the `Customer` class? Try changing your property from `id` to `customerId` in `Customer` class or specify the same using the `@Column('customerId')` annotation – Omkar Puttagunta Dec 02 '15 at 11:56

0 Answers0