我有 3 张桌子:
customer(idCustomer,...)is_managed(idCustomer,idPerson)sales_person(idPerson,...)
和之间存在@ManyToMany关系。customersales_person
当我执行删除时,它工作正常:customer和is_managed被sales_person删除。
但是当我执行更新时,customerandis_managed会更新,但sales_person不会。
例如,如果我customer通过删除更新 a sales_person,它会在is_managed表中删除,但不会在sales_person表中删除。
这是如何引起的,我该如何解决?
以下是相关代码:
// update customer
public String updateCustomer(Customer customer,ArrayList<Sales_person> sales_persons,ArrayList<Involved_group_relation> involved_groups, Macro_market macro_market)throws IOException {
// insert the sales_person attached to the customer
ArrayList<Sales_person> sales_personC = new ArrayList<Sales_person>();
sales_personC.addAll(sales_persons);
customer.setSalesPersons_BelongTo(sales_personC); // insert in customer the sales_persons
em.merge(customer);
return customer.getNameCustomer();
}
// entity customer
@Entity
@Table(name="customer")
public class Customer implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue( strategy = GenerationType.IDENTITY)
private Long idCustomer;
private String titleTypeAccount;
private String nameCustomer;
/** RELATIONS **/
// CUSTOMER - SALES_PERSON
@ManyToMany(
cascade={CascadeType.ALL}
)
@JoinTable(
name="is_managed",
joinColumns=@JoinColumn(name="idCustomer"),
inverseJoinColumns=@JoinColumn(name="idPerson")
)
private Collection<Sales_person> salesPersons_BelongTo;
...
...
// entity sales_person
@Entity
@Table(name="sales_person")
public class Sales_person implements Serializable {
private static final long serialVersionUID = 1L;
@Id
private Long idPerson;
private String nameSalesPerson;
private String jobFunction;
private String titleOrganization;
@ManyToMany(
mappedBy="salesPersons_BelongTo"
)
private Collection<Customer> customers;
...
...