I'm using JPA and Hibernate as provider with MySQL DBMS and I remarked that the cascade deleting does not work for my situation :
@Entity
public class Entity_1{
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
private String nomAttribute;
@ManyToMany(cascade={CascadeType.PERSIST, CascadeType.REMOVE})
private java.util.List<Entity_2> et2;
...
}
and the second Entity is
@Entity
public class Entity_2{
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private int id;
private String nomAttribute;
...
}
the result is a three tables
Entity_1 ,Entity_2, Entity_1_Entity_2
I remarked that when I delete a Entity_1 the Entity_2 is too deleted because of the cascade on deleting .
what I want is when I delete Entity_1 the relation between Entity_1 and Entity_2 deleted only not the Entity_2 and I tried Many options in but all in vain
What the option should I use or there are no options for that and I should use Triggers ??