You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Adam Hardy <ad...@cyberspaceroad.com> on 2009/06/27 00:20:55 UTC
execution order of sql statements for multiple persists and updates
Hi All,
I have played with this all day and managed to find one work-around but I can't
really live with it for long - I hope I'm just missing something in my config
but I can't work out what:
I have four entities, a grandparent, two parents (each with many-to-one with the
grandparent) and one grandchild (related many-to-one to both parents). (And all
are bi-directional).
OpenJPA 1.2 is having problems ordering the inserts and updates when I'm adding
new entities and seems to ignore my metadata.
Despite setting nullable=false insertable=true updatable=false on the grandchild
join-column definition, I see grandchild is inserted first without the parent
foreign keys and then next the parent is inserted, after which OpenJPA issues an
UPDATE on the grandchild. This breaks the referential integrity constraints when
the INSERT executes.
Perhaps the cascading is important? I have tried cascading only through one
parent from grandparent to grandchild, and then through the other, and also by
allowing both to cascade (cascade-all) but only one configuration works which is
when I'm persisting everything. If I try it with an existing grandparent, I
can't get it to work.
Thanks in advance for any help
Adam
Re: execution order of sql statements for multiple persists and updates
Posted by Adam Hardy <ad...@cyberspaceroad.com>.
I tried all those suggestions including the properties:
openjpa.jdbc.SchemaFactory=native(ForeignKeys=true)
openjpa.jdbc.MappingDefaults=ForeignKeyDeleteAction=restrict,
JoinForeignKeyDeleteAction=restrict
openjpa.jdbc.UpdateManager=operation-order
I tried many different permutations of cascading but had no luck, and in fact I
didn't want to say it but it looks like the fault is random, or rather that the
operations are executed randomly either one way (which breaks one reference) or
another way (which breaks a different reference) but there is no way I can force
them to execute the right way.
Regards
Adam
Miłosz Tylenda on 27/06/09 08:34, wrote:
> Have you tried the ideas presented in that post [1] and FAQ [2]?
>
> [1] http://n2.nabble.com/Inconsistent-behaviour-with-Bi-directional-One-to-Many-Mapping.-tp2570464p2570464.html
> [2] http://openjpa.apache.org/faq.html
>
>> Hi All,
>>
>> I have played with this all day and managed to find one work-around but I can't
>> really live with it for long - I hope I'm just missing something in my config
>> but I can't work out what:
>>
>> I have four entities, a grandparent, two parents (each with many-to-one with the
>> grandparent) and one grandchild (related many-to-one to both parents). (And all
>> are bi-directional).
>>
>> OpenJPA 1.2 is having problems ordering the inserts and updates when I'm adding
>> new entities and seems to ignore my metadata.
>>
>> Despite setting nullable=false insertable=true updatable=false on the grandchild
>> join-column definition, I see grandchild is inserted first without the parent
>> foreign keys and then next the parent is inserted, after which OpenJPA issues an
>> UPDATE on the grandchild. This breaks the referential integrity constraints when
>> the INSERT executes.
>>
>> Perhaps the cascading is important? I have tried cascading only through one
>> parent from grandparent to grandchild, and then through the other, and also by
>> allowing both to cascade (cascade-all) but only one configuration works which is
>> when I'm persisting everything. If I try it with an existing grandparent, I
>> can't get it to work.
Re: execution order of sql statements for multiple persists and updates
Posted by Miłosz Tylenda <mt...@o2.pl>.
Adam,
Have you tried the ideas presented in that post [1] and FAQ [2]?
Greetings,
Milosz
[1] http://n2.nabble.com/Inconsistent-behaviour-with-Bi-directional-One-to-Many-Mapping.-tp2570464p2570464.html
[2] http://openjpa.apache.org/faq.html
> Hi All,
>
> I have played with this all day and managed to find one work-around but I can't
> really live with it for long - I hope I'm just missing something in my config
> but I can't work out what:
>
> I have four entities, a grandparent, two parents (each with many-to-one with the
> grandparent) and one grandchild (related many-to-one to both parents). (And all
> are bi-directional).
>
> OpenJPA 1.2 is having problems ordering the inserts and updates when I'm adding
> new entities and seems to ignore my metadata.
>
> Despite setting nullable=false insertable=true updatable=false on the grandchild
> join-column definition, I see grandchild is inserted first without the parent
> foreign keys and then next the parent is inserted, after which OpenJPA issues an
> UPDATE on the grandchild. This breaks the referential integrity constraints when
> the INSERT executes.
>
> Perhaps the cascading is important? I have tried cascading only through one
> parent from grandparent to grandchild, and then through the other, and also by
> allowing both to cascade (cascade-all) but only one configuration works which is
> when I'm persisting everything. If I try it with an existing grandparent, I
> can't get it to work.
>
> Thanks in advance for any help
>
> Adam
>
>