You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Patrick Shea <pa...@ps1.net> on 2008/08/04 15:27:21 UTC

OpenJPA persists children before parent!

I have a very simple parent/child entity setup with a onetomany from the parent and manytoone on the child.

I create the parent, create the child, add the child to the parent collection and persist the parent.

At that point OpenJPA is trying to insert the child before the parent which results in a parent not found fk violation.

I'm I missing something or to I have to manually persist the parent first then add the children?

Patrick


Re: OpenJPA persists children before parent!

Posted by Pinaki Poddar <pp...@apache.org>.
OpenJPA can order the SQL statements to satisfy the foreign key constraints.
However, you must tell OpenJPA about the existing foreign keys; otherwise,
by default, it does neither read physical foreign key information from the
database, nor creates foreign key constrainst while defining schema for new
tables.

The information on how to tell OpenJPA about foreign keys is available in
FAQ [1]

[1] http://openjpa.apache.org/faq.html

-- 
View this message in context: http://n2.nabble.com/OpenJPA-persists-children-before-parent%21-tp668432p668724.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.