Hi Adam - Sorry if the reference was irrelevant.
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?
- Paul
On 4/15/2009 4:03 PM, Adam Hardy wrote:
Hi Paul,
surely you don't mean
http://issues.apache.org/jira/browse/OPENJPA-1004 ? Seems completely
unrelated.
I use both of these settings:
openjpa.jdbc.SchemaFactory=native(ForeignKeys=true)
openjpa.jdbc.MappingDefaults=ForeignKeyDeleteAction=restrict,
JoinForeignKeyDeleteAction=restrict
but they don't affect the issue.
I don't actually use forward mapping, although I'm looking for a
window to try it out. I have the foreign keys constraints hard wired
in a schema ddl script.
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:
Hi Adam -
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.
What I found in my app is that OpenJPA generates (forward mapping)
indices that work the way foreign keys do, except that OpenJPA
manages the relationships rather than having the database do it with
foreign keys. For instance I found that OpenJPA by default does
"effective" cascade delete on ManyToMany relations. This surprised
me a little since I did not find where that is in the spec (this is
the sensible default behavior though).
Perhaps others can enlighten on these issues further :-)
- Paul
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.
Regards
Adam