Insert called before delete in a collection with unique constraint
Hi all,
I have a simple @OneToMany private mapping:
private Collection<Item> items;
@OneToMany(mappedBy = "parent", cascade = CascadeType.ALL)
public Collection<Item> getItems() {
return items;
}
public void setItems(Collection<Item> items) {
this.items = items;
}
public void customize(ClassDescriptor classDescriptor) throws Exception {
OneToManyMapping mapping = (OneToManyMapping)
classDescriptor.getMappingForAttributeName("items");
mapping.privateOwnedRelationship();
}
I have a unique constraint on my Items table that a certain value cannot be duplicated.
My problem appears when I remove a previously saved item from the collection and add a new item containing the same data, at the same time.
After I save the parent and do a flush, I receive SQLIntegrityConstraintViolationException because TopLink performs first an insert query instead of deleting the existing item.
I tested the application and everything went fine with: remove item / save parent / insert item / save parent
I checked on the Internet and the documentation but didn't find anything similar to my problem. I tried debugging TopLink's internal calls but I'm missing some general ideas about all the inner workings and don't know what to look for. I use TopLink version: Oracle TopLink Essentials - 2.1 (Build b60e-fcs (12/23/2008))
Does anyone have a hint of what to look for?
Edited by: wise_guybg on Sep 25, 2009 4:01 PM
Edited by: wise_guybg on Oct 5, 2009 11:22 AM