Boblitz John wrote:
> 
> I might be wrong here - but it would seem to me that you are trying
> to persist the child, not the parent.  
> 
> In your definition "A" has a foreign key to "B" which means "B" must
> exist prior to "A" and is thus the parent in the relationship.  This is
> also what the error message said "parent key not found".
> 
> Have you tried persisting "B" instead of "A"?
> 
I agree that B must exist prior to A. But in my understanding the parent is
referenced by the mappedBy attribute which we have defined in entity B, so A
is the parent. I had expected JPA to recognize this relationship and execute
the statements in the correct order. But as Kevin explained OpenJPA has
tried and failed to detect the relationship unfortunately. I don't think
that persisting B instead of A is the right way (well I haven't tried it).

IMHO one advantage to use JPA is that it simplifies the way to work with
data and takes the burden to generate the proper SQL statements. Otherwise
developers could use plain JDBC and pay attention to all relationships on
their own. There would be no reason to use JPA.

--
View this message in context: 
http://openjpa.208410.n2.nabble.com/Constraint-violation-using-OneToOne-relationship-tp6978223p6996720.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Reply via email to