Hi,
I face a weird problem with the following relationship.
I have an Organisation, which can have Users and Groups. Users and Groups are associate to each other.
I have a UserGroup entity, to represent the link table, as I prefer not to have ManyToMany relation b/w user and group.
Now, If I delete User, the UserGroup association need to be deleted.
The same should happen if I delete Group also. So far everything is good.
But now, when I delete Organisation, cascade is happening on both User and Group. This in turn, tries to delete the same UserGroup association twice. This is causing OptimisticLockException.
I tried Cascade, ForeignKey, Dependent in all possible ways :-). But nothing is working.
I have 3 questions.
1. Is there any way to achieve the above functionality?
2. Why OpenJPA throws OptimisticLockException, if I try to delete the same row twice inside a single transaction?
3. Can OpenJPA resolve this kind of two way relations smartly? I mean only one delete should be fired.
Thanks,
Srinivasan Krishamoorthy.