2017-03-23 21 views
0

私はコレクションを含むオブジェクトを持っています。そして、親オブジェクトを削除した後、このコレクション内のすべてのオブジェクトを削除します。ここで親オブジェクトを削除してコレクションからDATABASEを削除するにはどうすればよいですか?

はRessource

@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 
} 
+0

である私のモデルで質問を修正してください:データベースから削除します。 –

答えて

0
@OneToMany(cascade = CascadeType.ALL,mappedBy="ressource") 
    private Collection<Affectation> affectations; 
+0

ありがとう、私はオプションのカスケードを忘れていたことを忘れてしまった。初心者のエラー:D –

関連する問題