Note that there are some explanatory texts on larger screens.

plurals
  1. POJPA Many to Many cascade problem
    primarykey
    data
    text
    <p>If I create a Customer and Controller, then associate my Controller with a customer it saves fine.</p> <p>If I then remove my controller it doesn't remove the relationship between them. This causes an EntityNotFoundException when I load the Customer.</p> <pre><code>javax.persistence.EntityNotFoundException: Unable to find Controller with id 22 </code></pre> <p>I'd like to know how to map this so that when a Controller is deleted the relationship is also deleted.</p> <p>Database Tables</p> <ul> <li>customer </li> <li>controller</li> <li>customer_controllers - mapping table.</li> </ul> <p>The Controller's id is not getting removed from the customer_controllers mapping table.</p> <pre><code>@Entity public class Customer implements Serializable{ private Integer id; private Set&lt;Controller&gt; controllers; @Id @GeneratedValue public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } @ManyToMany(cascade={CascadeType.ALL}) public Set&lt;Controller&gt; getControllers() { return controllers; } public void setControllers(Set&lt;Controller&gt; controllers) { this.controllers = controllers; } } @Entity public class Controller implements Serializable{ private Integer id; private String name; private String abbreviation; @Id @GeneratedValue public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getAbbreviation() { return abbreviation; } public void setAbbreviation(String abbreviation) { this.abbreviation = abbreviation; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload