You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Andrea Biasillo <ab...@dataloy.com> on 2016/05/12 08:15:55 UTC

Reordering of database operations causes violation of unique constraint

Hi!

My name is Andrea Biasillo, I am software architect in Dataloy AS, Bergen
Norway. In one of our project we use Cayenne as ORM. Unfortunately we are
facing the same problem reported by this case:

https://issues.apache.org/jira/browse/CAY-1898

Is  this case never  been taken in consideration? Is there a solution or at
least a work-wround?

Many regards

-- 

Andrea Biasillo - Dataloy Systems

P: +47 55 36 03 00

M: +4746542580 <%2B47%2055%2036%2003%2000>

Dataloy Service Desk <http://support.dataloy.com/>

Dataloy Knowledge Base <http://kb.dataloy.com/>

Subscribe to the Dataloy Newsletter <http://dataloy-systems.com/?page_id=591>

twitter.com/dataloy

www.dataloy-systems.com

Re: Reordering of database operations causes violation of unique constraint

Posted by Andrus Adamchik <an...@objectstyle.org>.
Certainly would be nice to fix CAY-1898. Can't say when we get to it, but it is certainly in the queue. And patches/pull requests are welcome ;) 

Andrus

> On May 18, 2016, at 9:38 AM, Andrea Biasillo <ab...@dataloy.com> wrote:
> 
> Hi!
> 
> First sorry for my late reply, but here in Norway there have been some bank holiday that gave us almost a free week, not BAD!
> 
> Second thank you very much for your response, it was very useful. Actually we had already implemented your solution, but for a bug to our exceptions framework the RunTime exception was not thrown to our application server so the transaction was not rolled back. This missed leading us let thinking that the Cayenne commitChanges() some how forced  the database commit. But after reading your reply we discovered the problem and now everything works fine. Of course would be be better to have just one commitChanges and let Cayenne to care about the order of CREATE, UPDATE and DELETE, do you have any plans for this?
> 
> Many regards
> 
> On Thu, May 12, 2016 at 4:12 PM, Andrus Adamchik <an...@objectstyle.org> wrote:
> Re-reading CAY-1898, it is about unique constraints, not FK constraints. So this is not about cycles, and my explanation does not apply :) The first workaround applies though (which is the same as what Ari had suggested in the original reply: https://lists.apache.org/thread.html/Z8c9iuyg8obghec )
> 
> Andrus
> 
> 
> > On May 12, 2016, at 7:08 AM, Andrus Adamchik <an...@objectstyle.org> wrote:
> >
> > Hi Andrea,
> >
> > We saw your message to dev@ already, and there was a reply:
> >
> > https://lists.apache.org/thread.html/Z8c9iuyg8obghec
> >
> > I guess you haven't seen it as the reply was sent to the list, not to you directly. So now I am including your address in cc:.
> >
> > Now back to your question. Cayenne does operation ordering to satisfy the constraints. But the graph sort algorithm has a few known limitations. Namely it doesn't know how to order dependency cycles (e.g. Employee -> Department -> Manager, who is also an employee). Those have to be resoled manually. There are two solutions:
> >
> > * Manual two-step commits - helps to resolve real cycles, when there's no valid ordering satisfying the constraints at all.
> > * @SortWeight annotation, which forces a certain predefined commit order between two or more entities. It helps to resolve cases with "virtual" cycles (where Cayenne thinks there's a cycle, but the actual commit still has a valid operation ordering that satisfies constraints).
> >
> > Andrus
> >
> >> On May 12, 2016, at 1:15 AM, Andrea Biasillo <ab...@dataloy.com> wrote:
> >>
> >> Hi!
> >>
> >> My name is Andrea Biasillo, I am software architect in Dataloy AS, Bergen
> >> Norway. In one of our project we use Cayenne as ORM. Unfortunately we are
> >> facing the same problem reported by this case:
> >>
> >> https://issues.apache.org/jira/browse/CAY-1898
> >>
> >> Is  this case never  been taken in consideration? Is there a solution or at
> >> least a work-wround?
> >>
> >> Many regards
> >>
> >> --
> >>
> >> Andrea Biasillo - Dataloy Systems
> >>
> >> P: +47 55 36 03 00
> >>
> >> M: +4746542580 <%2B47%2055%2036%2003%2000>
> >>
> >> Dataloy Service Desk <http://support.dataloy.com/>
> >>
> >> Dataloy Knowledge Base <http://kb.dataloy.com/>
> >>
> >> Subscribe to the Dataloy Newsletter <http://dataloy-systems.com/?page_id=591>
> >>
> >> twitter.com/dataloy
> >>
> >> www.dataloy-systems.com
> >
> 
> 
> 
> 
> -- 
> Andrea Biasillo - Dataloy Systems
> P: +47 55 36 03 00
> M: +4746542580
> Dataloy Service Desk
> Dataloy Knowledge Base
> Subscribe to the Dataloy Newsletter
> twitter.com/dataloy  
> www.dataloy-systems.com
> 


Re: Reordering of database operations causes violation of unique constraint

Posted by Andrea Biasillo <ab...@dataloy.com>.
Hi!

First sorry for my late reply, but here in Norway there have been some bank
holiday that gave us almost a free week, not BAD!

Second thank you very much for your response, it was very useful. Actually
we had already implemented your solution, but for a bug to our exceptions
framework the RunTime exception was not thrown to our application server so
the transaction was not rolled back. This missed leading us let thinking
that the Cayenne commitChanges() some how forced  the database commit. But
after reading your reply we discovered the problem and now everything works
fine. Of course would be be better to have just one commitChanges and let
Cayenne to care about the order of CREATE, UPDATE and DELETE, do you have
any plans for this?

Many regards

On Thu, May 12, 2016 at 4:12 PM, Andrus Adamchik <an...@objectstyle.org>
wrote:

> Re-reading CAY-1898, it is about unique constraints, not FK constraints.
> So this is not about cycles, and my explanation does not apply :) The first
> workaround applies though (which is the same as what Ari had suggested in
> the original reply: https://lists.apache.org/thread.html/Z8c9iuyg8obghec )
>
> Andrus
>
>
> > On May 12, 2016, at 7:08 AM, Andrus Adamchik <an...@objectstyle.org>
> wrote:
> >
> > Hi Andrea,
> >
> > We saw your message to dev@ already, and there was a reply:
> >
> > https://lists.apache.org/thread.html/Z8c9iuyg8obghec
> >
> > I guess you haven't seen it as the reply was sent to the list, not to
> you directly. So now I am including your address in cc:.
> >
> > Now back to your question. Cayenne does operation ordering to satisfy
> the constraints. But the graph sort algorithm has a few known limitations.
> Namely it doesn't know how to order dependency cycles (e.g. Employee ->
> Department -> Manager, who is also an employee). Those have to be resoled
> manually. There are two solutions:
> >
> > * Manual two-step commits - helps to resolve real cycles, when there's
> no valid ordering satisfying the constraints at all.
> > * @SortWeight annotation, which forces a certain predefined commit order
> between two or more entities. It helps to resolve cases with "virtual"
> cycles (where Cayenne thinks there's a cycle, but the actual commit still
> has a valid operation ordering that satisfies constraints).
> >
> > Andrus
> >
> >> On May 12, 2016, at 1:15 AM, Andrea Biasillo <ab...@dataloy.com> wrote:
> >>
> >> Hi!
> >>
> >> My name is Andrea Biasillo, I am software architect in Dataloy AS,
> Bergen
> >> Norway. In one of our project we use Cayenne as ORM. Unfortunately we
> are
> >> facing the same problem reported by this case:
> >>
> >> https://issues.apache.org/jira/browse/CAY-1898
> >>
> >> Is  this case never  been taken in consideration? Is there a solution
> or at
> >> least a work-wround?
> >>
> >> Many regards
> >>
> >> --
> >>
> >> Andrea Biasillo - Dataloy Systems
> >>
> >> P: +47 55 36 03 00
> >>
> >> M: +4746542580 <%2B47%2055%2036%2003%2000>
> >>
> >> Dataloy Service Desk <http://support.dataloy.com/>
> >>
> >> Dataloy Knowledge Base <http://kb.dataloy.com/>
> >>
> >> Subscribe to the Dataloy Newsletter <
> http://dataloy-systems.com/?page_id=591>
> >>
> >> twitter.com/dataloy
> >>
> >> www.dataloy-systems.com
> >
>
>


-- 

Andrea Biasillo - Dataloy Systems

P: +47 55 36 03 00

M: +4746542580 <%2B47%2055%2036%2003%2000>

Dataloy Service Desk <http://support.dataloy.com/>

Dataloy Knowledge Base <http://kb.dataloy.com/>

Subscribe to the Dataloy Newsletter <http://dataloy-systems.com/?page_id=591>

twitter.com/dataloy

www.dataloy-systems.com

Re: Reordering of database operations causes violation of unique constraint

Posted by Andrus Adamchik <an...@objectstyle.org>.
Re-reading CAY-1898, it is about unique constraints, not FK constraints. So this is not about cycles, and my explanation does not apply :) The first workaround applies though (which is the same as what Ari had suggested in the original reply: https://lists.apache.org/thread.html/Z8c9iuyg8obghec )

Andrus


> On May 12, 2016, at 7:08 AM, Andrus Adamchik <an...@objectstyle.org> wrote:
> 
> Hi Andrea,
> 
> We saw your message to dev@ already, and there was a reply:
> 
> https://lists.apache.org/thread.html/Z8c9iuyg8obghec
> 
> I guess you haven't seen it as the reply was sent to the list, not to you directly. So now I am including your address in cc:. 
> 
> Now back to your question. Cayenne does operation ordering to satisfy the constraints. But the graph sort algorithm has a few known limitations. Namely it doesn't know how to order dependency cycles (e.g. Employee -> Department -> Manager, who is also an employee). Those have to be resoled manually. There are two solutions:
> 
> * Manual two-step commits - helps to resolve real cycles, when there's no valid ordering satisfying the constraints at all.
> * @SortWeight annotation, which forces a certain predefined commit order between two or more entities. It helps to resolve cases with "virtual" cycles (where Cayenne thinks there's a cycle, but the actual commit still has a valid operation ordering that satisfies constraints).
> 
> Andrus
> 
>> On May 12, 2016, at 1:15 AM, Andrea Biasillo <ab...@dataloy.com> wrote:
>> 
>> Hi!
>> 
>> My name is Andrea Biasillo, I am software architect in Dataloy AS, Bergen
>> Norway. In one of our project we use Cayenne as ORM. Unfortunately we are
>> facing the same problem reported by this case:
>> 
>> https://issues.apache.org/jira/browse/CAY-1898
>> 
>> Is  this case never  been taken in consideration? Is there a solution or at
>> least a work-wround?
>> 
>> Many regards
>> 
>> -- 
>> 
>> Andrea Biasillo - Dataloy Systems
>> 
>> P: +47 55 36 03 00
>> 
>> M: +4746542580 <%2B47%2055%2036%2003%2000>
>> 
>> Dataloy Service Desk <http://support.dataloy.com/>
>> 
>> Dataloy Knowledge Base <http://kb.dataloy.com/>
>> 
>> Subscribe to the Dataloy Newsletter <http://dataloy-systems.com/?page_id=591>
>> 
>> twitter.com/dataloy
>> 
>> www.dataloy-systems.com
> 


Re: Reordering of database operations causes violation of unique constraint

Posted by Andrus Adamchik <an...@objectstyle.org>.
Hi Andrea,

We saw your message to dev@ already, and there was a reply:

https://lists.apache.org/thread.html/Z8c9iuyg8obghec

I guess you haven't seen it as the reply was sent to the list, not to you directly. So now I am including your address in cc:. 

Now back to your question. Cayenne does operation ordering to satisfy the constraints. But the graph sort algorithm has a few known limitations. Namely it doesn't know how to order dependency cycles (e.g. Employee -> Department -> Manager, who is also an employee). Those have to be resoled manually. There are two solutions:

* Manual two-step commits - helps to resolve real cycles, when there's no valid ordering satisfying the constraints at all.
* @SortWeight annotation, which forces a certain predefined commit order between two or more entities. It helps to resolve cases with "virtual" cycles (where Cayenne thinks there's a cycle, but the actual commit still has a valid operation ordering that satisfies constraints).

Andrus

> On May 12, 2016, at 1:15 AM, Andrea Biasillo <ab...@dataloy.com> wrote:
> 
> Hi!
> 
> My name is Andrea Biasillo, I am software architect in Dataloy AS, Bergen
> Norway. In one of our project we use Cayenne as ORM. Unfortunately we are
> facing the same problem reported by this case:
> 
> https://issues.apache.org/jira/browse/CAY-1898
> 
> Is  this case never  been taken in consideration? Is there a solution or at
> least a work-wround?
> 
> Many regards
> 
> -- 
> 
> Andrea Biasillo - Dataloy Systems
> 
> P: +47 55 36 03 00
> 
> M: +4746542580 <%2B47%2055%2036%2003%2000>
> 
> Dataloy Service Desk <http://support.dataloy.com/>
> 
> Dataloy Knowledge Base <http://kb.dataloy.com/>
> 
> Subscribe to the Dataloy Newsletter <http://dataloy-systems.com/?page_id=591>
> 
> twitter.com/dataloy
> 
> www.dataloy-systems.com