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/05/11 11:53:18 UTC

Re: cascading deletes and entity relationship constraints

Just a quick apology up-front because I haven't had time to follow up my problem 
myself. I fully intend to at some point soon, but in the meantime, I am having 
problems with cascading inserts, which I think may be closely related, so I 
thought I'd add it into this thread.

I create a child and a parent entity in the same transaction, and call the 
EntityManager operations on the child. It seems from my current state that 
OpenJPA is trying to insert the child before the parent, which won't work due to 
the referential integrity constraints on the child table.

Due to time pressure at the moment I'm going to work around it by swapping over 
the calls and pass in the parent to the entity manager.


Paul Copeland on 16/04/09 05:02, wrote:
> Are you saying that CascadeType.REMOVE does not propagate through 
> multiple levels of OneToMany relations and this only happens when using 
> database foreign keys?
> 
> The SQL errors in JIRA-39 look like they might be due to operation 
> ordering - hence the suggestion to use the UpdateManager setting below - 
> The documentation is very brief so it is unclear when you need that 
> setting and why it isn't the default in the first place - apparently you 
> lose some batch statement efficiency?
> 
> Side question - is the database schema reflection that happens with 
> openjpa.jdbc.SchemaFactory=native(ForeignKeys=true)  expensive?  Does 
> this only happen once per EntityManagerFactory?
> 
> On 4/15/2009 4:03 PM, Adam Hardy wrote:
>>
>> My observation is that one level of parent-child relationship 
>> cascading will work, but OpenJPA won't descend the relationship tree 
>> any further.
>>
>>
>> Paul Copeland on 15/04/09 23:28, wrote:
>>> JIRA-39 is pretty old. Possibly JIRA-1004 is related to your 
>>> question? There was recent discussion on this list about this.
>>>
>>> Also there was recent mention on this list of using either one of 
>>> these settings regarding ordering of operations (reading the docs 
>>> leaves me with some questions about what these do).
>>>
>>>  <property name="openjpa.jdbc.Schemafactory" 
>>> value="native(ForeignKeys=true)"/>
>>>
>>>  <property name="openjpa.jdbc.UpdateManager" value="operation-order"/>
>>>
>>> It seems like by default (this is just my observation) OpenJPA 
>>> manages "effective" foreign key behavior without actually generating 
>>> foreign keys when it does forward mapping.  If you have existing 
>>> foreign keys on a database or the database is updated by non-JPA 
>>> clients then you might need to apply annotations and configuration to 
>>> account for that.
>>>
>>> On 4/12/2009 7:31 PM, Adam Hardy wrote:
>>>> Just wanted to check that this old issue still describes the 
>>>> situation properly:
>>>>
>>>> http://issues.apache.org/jira/browse/OPENJPA-39
>>>> Cascade delete does not work with foreign key constraints
>>>>
>>>> - marked as 'resolved - wont fix'.
>>>>
>>>> Just wondering if maybe in the in-between time something has been 
>>>> implemented for this.
>>>>
>>>> I'm trying to do exactly this (delete a large part of my object 
>>>> model cascading down several parent-child relationships) but I can't 
>>>> get it to work.