You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Borut Bolčina <bo...@najdi.si> on 2006/10/09 15:43:47 UTC

Re: Parent/Child Insert ordering (was: Caching problem?)

Hi,

in API docs for org.objectstyle.cayenne.map.AshwoodEntitySorter it says:

    "...Presently it works for acyclic database schemas with possible
    multi-reflexive tables. The class uses topological sorting from the
    Ashwood library <http://objectstyle.org/ashwood/>."

What are multi-reflexive tables? I guess not every reflexive 
relationship is cyclic. If db row "points" to the same db row then it 
would be cyclic (for example - someone is his/her own manager), 
otherwise just reflexive. Is this correct?

-Borut

On 21.5.2006 19:24, Andrus Adamchik wrote:
> Cayenne handles correct ordering of operations automatically, based on 
> dependencies derived from relationships.The algorithm has a few 
> limitations though. It can't handle cycles (when Entity A depends on 
> Entity B, but also Entity B depends on Entity A). This probably also 
> includes entities that have relationships to the same entity (I assume 
> this is the case the original post was referring to).
>
> There are few solutions:
>
> 1. (a workaround, rather than a solution) Do commit in two steps.
> 2. Define FK constraints in question as DEFERRABLE and INITIALLY 
> DEFERRED (supported by Postgres 8.*)
> 3. Set a custom org.objectstyle.cayenne.map.EntitySorter on the DataNode.
>
> Andrus
>
>
> On May 20, 2006, at 3:00 AM, Marcin Skladaniec wrote:
>
>> Hm. Strange. I do really complex commits, sometimes 7 or more related 
>> records (I mean 7 levels of relationship, not seven entities), 
>> related by many-to-many many-to-one relationships and never get those 
>> problems. And it doesn't matter if the records are new or old. Could 
>> you describe how you are creating objects and how do you commit them ?
>>
>> Regards
>> Marcin
>>
>> On 20/05/2006, at 4:31 PM, Tomi NA wrote:
>>
>>> On 5/20/06, Jeff de Vries <jd...@pfrog.com> wrote:
>>>> I don't know if it is related or not, but I've also had problems in 
>>>> the
>>>> past when I try to create a new parent and several child objects 
>>>> related
>>>> to that parent all at once and then try to commit.  The problem looks
>>>> like Cayenne is INSERTing the child records into the database first,
>>>> before the parent record, and the database complains that the children
>>>> have an invalid foreign key (and, yes, I have the ON UPDATE and ON
>>>> DELETE rules for the foreign key set to DO NOTHING and I still get the
>>>> error from PostgreSQL).  To get around it I just committed the parent
>>>> first, then committed all the children.
>>>
>>> I had the same problem, IIRC: I was very surprised that cayenne
>>> couldn't handle such a commit, although truth be told, I can't imagine
>>> everything that's going on under the hood of the operation that would
>>> make implementing this feature difficult.
>>> I would certainly love to see this fixed (if at all possible) as I
>>> wasn't to happy to have to commit in the middle of what had to be an
>>> atomic transaction. It'd also make the framework a lot more flexible,
>>> e.g. enabling the user to have long inter-commit sessions with complex
>>> data updates, if the user so desires.
>>>
>>> t.n.a.
>>
>>
>

-- 
bLOG <http://www.delo.si/blog/borutb/>
--
Naključna *izjava tedna* iz tednika Mladina:

Re: Parent/Child Insert ordering (was: Caching problem?)

Posted by Andrus Adamchik <an...@objectstyle.org>.
On Oct 9, 2006, at 9:43 AM, Borut Bolčina wrote:

> If db row "points" to the same db row then it would be cyclic (for  
> example - someone is his/her own manager), otherwise just  
> reflexive. Is this correct?

Ok, it is coming back to me... "multi-reflexive" simply means that  
there are multiple different relationships between the rows of the  
same table. So I wouldn't worry about single row pointing to self, as  
it doesn't violate constraints on insert, but say you have R1 and R2  
relationships within the same table (e.g. Category table;  
parentCategory and relatedCategory relationships). There is a chance  
that two or more rows will form a cycle: A -(parentCategory)-> B - 
(relatedCategory)-> A.

Andrus




Re: Parent/Child Insert ordering (was: Caching problem?)

Posted by Andrus Adamchik <an...@objectstyle.org>.
Good question :-) Andriy, our math geek, is no longer with us. I  
don't recall the details (need to dig through Ashwood I guess), but  
simple parent/child relationships within the same table used to work  
afaik... We may think of smarter strategies to resolve the cycles  
(such as a chain of insert/update queries in the same transaction)...  
I don't think this will happen soon though.

Andrus



On Oct 9, 2006, at 9:43 AM, Borut Bolčina wrote:
> Hi,
>
> in API docs for org.objectstyle.cayenne.map.AshwoodEntitySorter it  
> says:
> "...Presently it works for acyclic database schemas with possible  
> multi-reflexive tables. The class uses topological sorting from the  
> Ashwood library."
> What are multi-reflexive tables? I guess not every reflexive  
> relationship is cyclic. If db row "points" to the same db row then  
> it would be cyclic (for example - someone is his/her own manager),  
> otherwise just reflexive. Is this correct?
>
> -Borut
>
> On 21.5.2006 19:24, Andrus Adamchik wrote:
>> Cayenne handles correct ordering of operations automatically,  
>> based on dependencies derived from relationships.The algorithm has  
>> a few limitations though. It can't handle cycles (when Entity A  
>> depends on Entity B, but also Entity B depends on Entity A). This  
>> probably also includes entities that have relationships to the  
>> same entity (I assume this is the case the original post was  
>> referring to).
>>
>> There are few solutions:
>>
>> 1. (a workaround, rather than a solution) Do commit in two steps.
>> 2. Define FK constraints in question as DEFERRABLE and INITIALLY  
>> DEFERRED (supported by Postgres 8.*)
>> 3. Set a custom org.objectstyle.cayenne.map.EntitySorter on the  
>> DataNode.
>>
>> Andrus
>>
>>
>> On May 20, 2006, at 3:00 AM, Marcin Skladaniec wrote:
>>
>>> Hm. Strange. I do really complex commits, sometimes 7 or more  
>>> related records (I mean 7 levels of relationship, not seven  
>>> entities), related by many-to-many many-to-one relationships and  
>>> never get those problems. And it doesn't matter if the records  
>>> are new or old. Could you describe how you are creating objects  
>>> and how do you commit them ?
>>>
>>> Regards
>>> Marcin
>>>
>>> On 20/05/2006, at 4:31 PM, Tomi NA wrote:
>>>
>>>> On 5/20/06, Jeff de Vries <jd...@pfrog.com> wrote:
>>>>> I don't know if it is related or not, but I've also had  
>>>>> problems in the
>>>>> past when I try to create a new parent and several child  
>>>>> objects related
>>>>> to that parent all at once and then try to commit.  The problem  
>>>>> looks
>>>>> like Cayenne is INSERTing the child records into the database  
>>>>> first,
>>>>> before the parent record, and the database complains that the  
>>>>> children
>>>>> have an invalid foreign key (and, yes, I have the ON UPDATE and ON
>>>>> DELETE rules for the foreign key set to DO NOTHING and I still  
>>>>> get the
>>>>> error from PostgreSQL).  To get around it I just committed the  
>>>>> parent
>>>>> first, then committed all the children.
>>>>
>>>> I had the same problem, IIRC: I was very surprised that cayenne
>>>> couldn't handle such a commit, although truth be told, I can't  
>>>> imagine
>>>> everything that's going on under the hood of the operation that  
>>>> would
>>>> make implementing this feature difficult.
>>>> I would certainly love to see this fixed (if at all possible) as I
>>>> wasn't to happy to have to commit in the middle of what had to  
>>>> be an
>>>> atomic transaction. It'd also make the framework a lot more  
>>>> flexible,
>>>> e.g. enabling the user to have long inter-commit sessions with  
>>>> complex
>>>> data updates, if the user so desires.
>>>>
>>>> t.n.a.
>>>
>>>
>>
>
> -- 
> <blog-logo.gif>
>
> --
> Naključna izjava tedna iz tednika Mladina: