Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jpa deleting manytomany links

I have a table of events and i want to make groups of them. that is the easy easy

    // this cascade group still removes the join table but not the products table
@ManyToMany(targetEntity=Product.class,fetch = FetchType.EAGER, cascade = 
   {CascadeType.PERSIST, CascadeType.REFRESH,CascadeType.MERGE})
@JoinTable(name = "lcw_group_product", 
    joinColumns = { @JoinColumn(name = "group_id", referencedColumnName="id") }, 
    inverseJoinColumns = { @JoinColumn(name = "product_id", referencedColumnName="id") })
@ElementForeignKey(updateAction = ForeignKeyAction.CASCADE)
    public Set getProducts() {
        return products;
    }

These annotations work when i want to completely remove the group but when i want to update the group to remove some of the links, leaving the events still there, i can't find a way to do this, i am currently doing delete statements of the link table but this doesn't get reflected in the parent entity

like image 538
WendyG Avatar asked Jul 28 '10 08:07

WendyG


People also ask

How do I get rid of many-to-many?

To avoid this problem, you can break the many-to-many relationship into two one-to-many relationships by using a third table, called a join table. Each record in a join table includes a match field that contains the value of the primary keys of the two tables it joins.


1 Answers

Just to clarify that the ElementForeignKey is an OpenJPA annotation, not a JPA one. Unfortunately, so far there is no orphanRemoval attribute for the ManyToMany annotation.

like image 170
ichalos Avatar answered Oct 21 '22 08:10

ichalos