You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by "srini.krish" <sr...@gmail.com> on 2009/10/28 10:56:34 UTC

Getting OptimisticLockException when dealing with Link Tables

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.

-- 
View this message in context: http://n2.nabble.com/Getting-OptimisticLockException-when-dealing-with-Link-Tables-tp3904475p3904475.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: Getting OptimisticLockException when dealing with Link Tables

Posted by Pinaki Poddar <pp...@apache.org>.
> 3. Can OpenJPA resolve this kind of two way relations smartly? I mean only
one delete should be fired.

OpenJPA uses a fairly smart topological sort to order its SQL operations.
The algorithm is sufficeintly smart to detect many other cases where
ordering of generated SQL is critical in terms of satisfying existing
database constraints. Your observation suggests that the presented use case
where the same instance becomes a candidate for the delete set twice (or
more) is not handled.
  Please present your use case in its essential form with a reproducible
test case and we will follow it up.

  Regards --





srini.krish wrote:
> 
> 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.
> 
> 


-----
Pinaki 
-- 
View this message in context: http://n2.nabble.com/Getting-OptimisticLockException-when-dealing-with-Link-Tables-tp3904475p3909482.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.