Hello everybody! I'm a beginner in Hibernate, so excuse me if i'm not specific enough in my explanations. So, like it's mentionned in the title of the topic, in Many-to-Many relation delete and remove don't work.
I have the following relationship between: A <---> B M:N
The entity A contains a set of <B> objects and idem B contains a set of <A> objects.
Delete and Remove work fine until I began to introduice inheritance for my entity B: indeed, an object B can be of several types.
B
/ | \
/ | \
B1 B2 B3
in the joinTable between A and B, there are B1 and B2 objects. Before the inheritance, i just remove the B objects who are type 2 , so my list of B objects displayed at screen contains only B object type 1. When I remove or delete, it works fine. Since the introduction of inheritance, in A object, i have two sets: one of B1 objects and an other of B2 objects: I don't take care about the set of B2 objects, only the set of B1 objects matters to me. So now, i display the list of B1 objects, which of course, contains only B1 objects. And now, remove and delete don't work. I post the following function Remove:
side of A object:
Code:
@ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinTable(name = "AB",
joinColumns = { @JoinColumn(name = "ANo") },
inverseJoinColumns = { @JoinColumn(name = "BNo") })
@Where(clause = "Btypeno=1")
private Set<B1> b1 = null;
side of B1 Object:
Code:
@ManyToMany(mappedBy = "set B1 dans A", fetch = FetchType.LAZY)
private Set<A> a = new HashSet<A>();
function remove:Code:
public String removeBFromA() {
getContextA().getB1().remove(getContextB1());
return "cCreateOrModifyA";
}
In debug Mode, I can see that when I'm at the remove line, the B1 object is in the list once more. it seems remove doesn't want to work since I introduice the inheritance.
Someone has ever have this problem before? I'll be very glad if anybody could help me because I'm in training and i would finish my project!
Excuse me for my poor English, I'm french so don't be afraid if I use weird words or expressions.
Thanks for the future aid.