You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Scott Anderson <sa...@airvana.com> on 2008/04/07 21:04:08 UTC

Many-to-many bug?

Hi all,

 

I've got a many-to-many relationship. For one object, I'm trying to
clear all of the entries in the relational table, and then re-add them
BEFORE doing a commit. If I do this, Cayenne tries to do an INSERT and
then a DELETE, but this fails since the relational table has both fields
as PKs. My application must handle the condition where no action is
actually required on the database end, but it doesn't seem like the
application logic should be responsible for database quirks.

 

Is there a simple way to solve this? My temporary solution is to do a
commit after removing the relationships and before re-adding them.

 

Thanks,

Scott


Re: Many-to-many bug?

Posted by Andrus Adamchik <an...@objectstyle.org>.
I'd say we should handle this better... Please file an improvement  
request. I think this can be fixed with reasonable effort.

Thanks
Andrus


On Apr 7, 2008, at 10:04 PM, Scott Anderson wrote:

> Hi all,
>
>
>
> I've got a many-to-many relationship. For one object, I'm trying to
> clear all of the entries in the relational table, and then re-add them
> BEFORE doing a commit. If I do this, Cayenne tries to do an INSERT and
> then a DELETE, but this fails since the relational table has both  
> fields
> as PKs. My application must handle the condition where no action is
> actually required on the database end, but it doesn't seem like the
> application logic should be responsible for database quirks.
>
>
>
> Is there a simple way to solve this? My temporary solution is to do a
> commit after removing the relationships and before re-adding them.
>
>
>
> Thanks,
>
> Scott
>


Re: Many-to-many bug?

Posted by Alexis <al...@gmail.com>.
Hi,
I ran into the same issue, i guess.
Here's a summary : 
A <-->>RelAB<<-->B
I get all the RelAB for an A, remove all these objects, readd some new RelAB
to this A and a B and then commit, all of this in a dedicated datacontext.
In the logs, the inserts statements are generated as expected, the delete
statements are not.
Something weird is that dc.deletedObjects(); returns the correct objects to
be deleted before i do the commit(); so i guess there's a bug when
generating the statements corresponding to graph changes.
Or did i miss something ?

I use the same workaround as Scott, commit the changes after removing the
RelABs, but i would like to keep things transactionnal as much as
possible...

Thanks for your answer


Scott A wrote:
> 
> Hi all,
> 
>  
> 
> I've got a many-to-many relationship. For one object, I'm trying to
> clear all of the entries in the relational table, and then re-add them
> BEFORE doing a commit. If I do this, Cayenne tries to do an INSERT and
> then a DELETE, but this fails since the relational table has both fields
> as PKs. My application must handle the condition where no action is
> actually required on the database end, but it doesn't seem like the
> application logic should be responsible for database quirks.
> 
>  
> 
> Is there a simple way to solve this? My temporary solution is to do a
> commit after removing the relationships and before re-adding them.
> 
>  
> 
> Thanks,
> 
> Scott
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Many-to-many-bug--tp16548253p16698781.html
Sent from the Cayenne - User mailing list archive at Nabble.com.