Java Mailing List Archive

http://www.gg3721.com/

Home » users.openjpa »

Foreign key violation while persisting - statement order issue.

femski

2008-06-22

Replies: Find Java Web Hosting

Author LoginPost Reply

Folks !

I am getting foreign key violation error persisting a simple hierarchy of
objects which looks like below:

class SearchTask {
 collection of Search Log {
   Collections of A
   Collection of B
   Collection of C
   (A, B, C have one more layer of collections)
 }
}

class FreeSearch derived from Search Task using a discriminator {
 collection of Sources
}

Cascades are all set to ALL (on both sides of one-to-many relationships).

I expect it to persist SearchTask/FreeSearch first - generate its primary
key and substitute them in foreign key attributed of SearchLog and further
down. openJPA instead tries to insert A, B C etc before SearchLog. And
Sources before FreeSearch etc. As if it doesn't understand the hierarchy.

I am initializing collections in the constructors (using new ArrayList) and
populate them later. I have printed the graph to make sure everything is as
I would expect. Primary keys are generated by
OpenJPA correctly. It even sets foreign key values correctly. SQL logs shows
its a statement ordering issue.

When I completely dumb down the model and drop foreign key constraints then
it works - but only sometimes. Generated SQL log shows statement order is
random at best. Retry works sometimes. I haven't dropped all constraints and
tried persisting entire model. All my foreign keys are not null and I don't
want to change my design.

Even when I do manual persist walking down the tree in right order, inserts
are done in random order (even though I have read OpenJPA does not
reordering of its own) and fails because of foreign keys.

I am running OpenEJB 3.0 embedded inside Tomcat which no change to original
configuration. Database is Postgres 8.1.

What am I missing ?

Any help would be appreciated.

thank you,

-Sanjay Kumar

--
Sent from the OpenJPA Users mailing list archive at Nabble.com.

©2008 gg3721.com - Jax Systems, LLC, U.S.A.