How to delete entity with many to many relation? JPA

San Rembak :

i don't know how to delete this. Only one thing i noticed that the OrderToProvider will be deleted after deleting all entities in a table named "OrderToProvider-Goods".

Code:

OrderToProvider

public class OrderToProvider {
@GeneratedValue (strategy = GenerationType.IDENTITY)
@Id
private int id;
@Basic
private int price;
@Basic
private Date dataOfOrder;
@Basic
private Date dateOfProcessing;
@ManyToOne(optional = false)
private main.data.Provider provider;
@ManyToMany (cascade = CascadeType.ALL)
private Collection<Good> goods;

Good

public class Good implements Comparable<Good>{
    @GeneratedValue (strategy = GenerationType.IDENTITY)
    @Id
    private int id;
    @Basic
    private String name;
    @Basic
    private String model;
    @Basic
    private int price;
    @Basic
    private String type;
    @Basic
    private int amount;
    @ManyToOne(optional = false)
    private Provider provider;
Eteka Christopher :

To delete the OrderToProvider from your DB, first you retrieve it from your DB, then setGoods(null) and setProvider(null), then delete it afterwards. This should work with conditions that you have a properly implemented setters.

I hope this is helpful.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to delete an entity which has many to many relation with other tables?

How delete many-to-many relation in Entity Framework 6

JPA: How to have one-to-many relation of the same Entity type

JPA: how to persist many to many relation

How to find an entity containing a list of id (of the other entity) in a many-to-many relation on MySql/Jpa?

How to insert entity with many to many relation?

How to get deep relation in Entity Framework in many to many relation?

Many to Many Relation - Entity Framework

how to select child in one to many relation in jpa

How find entities by many to many relation entity id

How to add entries for many to many relation table with Entity Framework

how to query against a many to many relation with entity framework 6

How to query many to many relation using Entity Framework

JPA / Spring MVC Rest API - One to Many relation in the same Entity

Spring JPA Specification to filter one to many relation with child entity

JPA persit creates new existing entity in many to one relation

One-To-Many relation in JPA DELETE operation is not working

JPA many to many relation not inserting into generated table

Many to many relation not persisting in Spring JPA, Kotlin

Entity Framework: List of Ids for many to many relation

Entity Framework many to many relation error

Spring data JPA- Hibernate Many to Many relation is inserting null in link entity table

Many-to-many relation - automatically delete orphans

Many to many relation with ON DELETE CASCADE with Symfony and Doctrine

Groovy/Grails many-to-many delete relation

Delete on many to one relation is not persisting

How to Select Only Specific Children in One to Many Relation in JPA

detached entity passed to persist, many to many JPA

Spring jpa many to many lazy delete