Salut tous le monde ,

Voila, j'ai une table (PersistentReceptacleImpl) qui a une association manyToMany avec elle-même (associations):
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
@Table(name = "RECEPTACLE", uniqueConstraints = { @UniqueConstraint(columnNames = { "NESTING" }) })
@NamedQueries( { @NamedQuery(name = "allReceptacleQuery", query = "FROM PersistentReceptacleImpl t ORDER BY t.family.name, t.nesting") })
@Entity
public final class PersistentReceptacleImpl implements PersistentReceptacle, Serializable {
 
	private static final long serialVersionUID = -3124465908386690459L;
 
	@Id
	@GeneratedValue
	private Integer id = null;
 
	@ManyToOne(targetEntity = PersistentReceptacleFamilyImpl.class)
	@JoinColumn(name = "FAMILY_ID", nullable = false)
	private PersistentReceptacleFamily family = null;
 
	@Column(name = "NESTING", length = 50, nullable = false)
	private String nesting = null;
 
	@ManyToMany(targetEntity = PersistentReceptacleImpl.class, cascade = { CascadeType.PERSIST, CascadeType.MERGE })
	@JoinTable(name = "RECEPTACLE_ASSOCIATION", joinColumns = @JoinColumn(name = "RECEPTACLE_ID"), inverseJoinColumns = @JoinColumn(name = "ASSOCIATED_RECEPTACLE_ID"))
	private Collection<PersistentReceptacle> associations;
 
	public PersistentReceptacleImpl() {
		super();
	}
 
	public Integer getId() {
		return this.id;
	}
 
	public PersistentReceptacleFamily getFamily() {
		return this.family;
	}
 
	public void setFamily(final PersistentReceptacleFamily family) {
		this.family = family;
	}
 
	public String getNesting() {
		return this.nesting;
	}
 
	public void setNesting(final String nesting) {
		this.nesting = nesting;
	}
 
	public Collection<PersistentReceptacle> getAssociations() {
		if (this.associations == null) {
			this.associations = new LinkedHashSet<PersistentReceptacle>();
		}
		return this.associations;
	}
 
	@Override
	public boolean equals(final Object obj) {
		boolean result = false;
		if (obj == this) {
			result = true;
		} else if ((this.nesting != null) && (obj instanceof PersistentReceptacleImpl)) {
			result = this.nesting.equals(((PersistentReceptacleImpl) obj).nesting);
		}
		return result;
	}
 
	@Override
	public int hashCode() {
		int result = 0;
		if (this.nesting != null) {
			result = this.nesting.hashCode();
		}
		return result;
	}
 
	@Override
	public String toString() {
		return "PersistentReceptacle[" + this.nesting + "]";
	}
 
}
Mon soucis se situe lorsque je veux faire une suppression. Tel qu'elle, j'ai une erreur de violation de clé étrangère (table RECEPTACLE_ASSOCIATION), ce qui est normal. Par contre, si je met CascadeType.ALL:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
	@ManyToMany(targetEntity = PersistentReceptacleImpl.class, cascade = { CascadeType.ALL })
	@JoinTable(name = "RECEPTACLE_ASSOCIATION", joinColumns = @JoinColumn(name = "RECEPTACLE_ID"), inverseJoinColumns = @JoinColumn(name = "ASSOCIATED_RECEPTACLE_ID"))
	private Collection<PersistentReceptacle> associations;
il va bien me supprimer les enregistrements présents dans la table RECEPTACLE_ASSOCIATION (parfait, c'est ce que je veux), mais aussi les objets PersistentReceptacleImpl rattaché à cette table (c'est pas ce que je veux).

Y a t-il un moyen si je veux supprimer un objet PersistentReceptacleImpl, de supprimer les enregistrements de la table RECEPTACLE_ASSOCIATION rattachés à cet objet et c'est tout ? C'est à dire pas les objets eux-même, juste l'association.

Par avance, merci de votre aide ...

JP