如何通过删除父对象从数据库中删除一个集合?
How to delete from the DATABASE a collection by removing the parent object?
我有一个包含集合的对象。我想在删除父对象后删除此集合中的所有对象。
这是我的模型资源
@Entity
public class Ressource implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue
private Long idt_ressource;
private String nom;
private String prenom;
private String telephone;
private String matricule;
private String mail;
private Date dateEntree;
@OneToMany(mappedBy="ressource")
private Collection<Affectation> affectations;
// Getters, Setters and Construct
}
这是我的模型影响
@Entity
public class Affectation implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue
private Long idt_affectation;
private Date dateDebut;
private Date dateFin;
@ManyToOne
@JoinColumn(name="idt_ressource")
private Ressource ressource;
@ManyToOne
@JoinColumn(name="idt_structure")
private Structure structure;
// Getters, Setters and Construct
}
@OneToMany(cascade = CascadeType.ALL,mappedBy="ressource")
private Collection<Affectation> affectations;
我有一个包含集合的对象。我想在删除父对象后删除此集合中的所有对象。
这是我的模型资源
@Entity
public class Ressource implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue
private Long idt_ressource;
private String nom;
private String prenom;
private String telephone;
private String matricule;
private String mail;
private Date dateEntree;
@OneToMany(mappedBy="ressource")
private Collection<Affectation> affectations;
// Getters, Setters and Construct
}
这是我的模型影响
@Entity
public class Affectation implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue
private Long idt_affectation;
private Date dateDebut;
private Date dateFin;
@ManyToOne
@JoinColumn(name="idt_ressource")
private Ressource ressource;
@ManyToOne
@JoinColumn(name="idt_structure")
private Structure structure;
// Getters, Setters and Construct
}
@OneToMany(cascade = CascadeType.ALL,mappedBy="ressource")
private Collection<Affectation> affectations;